mirror of https://github.com/usual2970/certimate
				
				
				
			
		
			
				
	
	
		
			338 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			Go
		
	
	
			
		
		
	
	
			338 lines
		
	
	
		
			6.5 KiB
		
	
	
	
		
			Go
		
	
	
package migrations
 | 
						|
 | 
						|
import (
 | 
						|
	"encoding/json"
 | 
						|
 | 
						|
	"github.com/pocketbase/dbx"
 | 
						|
	"github.com/pocketbase/pocketbase/daos"
 | 
						|
	m "github.com/pocketbase/pocketbase/migrations"
 | 
						|
	"github.com/pocketbase/pocketbase/models"
 | 
						|
)
 | 
						|
 | 
						|
func init() {
 | 
						|
	m.Register(func(db dbx.Builder) error {
 | 
						|
		dao := daos.New(db);
 | 
						|
 | 
						|
		collection, err := dao.FindCollectionByNameOrId("z3p974ainxjqlvs")
 | 
						|
		if err != nil {
 | 
						|
			return err
 | 
						|
		}
 | 
						|
 | 
						|
		return dao.DeleteCollection(collection)
 | 
						|
	}, func(db dbx.Builder) error {
 | 
						|
		jsonData := `{
 | 
						|
			"id": "z3p974ainxjqlvs",
 | 
						|
			"created": "2024-07-29 10:02:48.334Z",
 | 
						|
			"updated": "2024-12-22 12:06:15.156Z",
 | 
						|
			"name": "domains",
 | 
						|
			"type": "base",
 | 
						|
			"system": false,
 | 
						|
			"schema": [
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "iuaerpl2",
 | 
						|
					"name": "domain",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "ukkhuw85",
 | 
						|
					"name": "email",
 | 
						|
					"type": "email",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"exceptDomains": null,
 | 
						|
						"onlyDomains": null
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "v98eebqq",
 | 
						|
					"name": "crontab",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "alc8e9ow",
 | 
						|
					"name": "access",
 | 
						|
					"type": "relation",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"collectionId": "4yzbv8urny5ja1e",
 | 
						|
						"cascadeDelete": false,
 | 
						|
						"minSelect": null,
 | 
						|
						"maxSelect": 1,
 | 
						|
						"displayFields": null
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "topsc9bj",
 | 
						|
					"name": "certUrl",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "vixgq072",
 | 
						|
					"name": "certStableUrl",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "g3a3sza5",
 | 
						|
					"name": "privateKey",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "gr6iouny",
 | 
						|
					"name": "certificate",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "tk6vnrmn",
 | 
						|
					"name": "issuerCertificate",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "sjo6ibse",
 | 
						|
					"name": "csr",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "x03n1bkj",
 | 
						|
					"name": "expiredAt",
 | 
						|
					"type": "date",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": "",
 | 
						|
						"max": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "srybpixz",
 | 
						|
					"name": "targetType",
 | 
						|
					"type": "select",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"maxSelect": 1,
 | 
						|
						"values": [
 | 
						|
							"aliyun-oss",
 | 
						|
							"aliyun-cdn",
 | 
						|
							"aliyun-dcdn",
 | 
						|
							"ssh",
 | 
						|
							"webhook",
 | 
						|
							"tencent-cdn",
 | 
						|
							"qiniu-cdn",
 | 
						|
							"local"
 | 
						|
						]
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "xy7yk0mb",
 | 
						|
					"name": "targetAccess",
 | 
						|
					"type": "relation",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"collectionId": "4yzbv8urny5ja1e",
 | 
						|
						"cascadeDelete": false,
 | 
						|
						"minSelect": null,
 | 
						|
						"maxSelect": 1,
 | 
						|
						"displayFields": null
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "6jqeyggw",
 | 
						|
					"name": "enabled",
 | 
						|
					"type": "bool",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "hdsjcchf",
 | 
						|
					"name": "deployed",
 | 
						|
					"type": "bool",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "aiya3rev",
 | 
						|
					"name": "rightnow",
 | 
						|
					"type": "bool",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "ixznmhzc",
 | 
						|
					"name": "lastDeployedAt",
 | 
						|
					"type": "date",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": "",
 | 
						|
						"max": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "zfnyj9he",
 | 
						|
					"name": "variables",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "g65gfh7a",
 | 
						|
					"name": "nameservers",
 | 
						|
					"type": "text",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"min": null,
 | 
						|
						"max": null,
 | 
						|
						"pattern": ""
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "wwrzc3jo",
 | 
						|
					"name": "applyConfig",
 | 
						|
					"type": "json",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"maxSize": 2000000
 | 
						|
					}
 | 
						|
				},
 | 
						|
				{
 | 
						|
					"system": false,
 | 
						|
					"id": "474iwy8r",
 | 
						|
					"name": "deployConfig",
 | 
						|
					"type": "json",
 | 
						|
					"required": false,
 | 
						|
					"presentable": false,
 | 
						|
					"unique": false,
 | 
						|
					"options": {
 | 
						|
						"maxSize": 2000000
 | 
						|
					}
 | 
						|
				}
 | 
						|
			],
 | 
						|
			"indexes": [
 | 
						|
				"CREATE UNIQUE INDEX ` + "`" + `idx_4ABO6EQ` + "`" + ` ON ` + "`" + `domains` + "`" + ` (` + "`" + `domain` + "`" + `)"
 | 
						|
			],
 | 
						|
			"listRule": null,
 | 
						|
			"viewRule": null,
 | 
						|
			"createRule": null,
 | 
						|
			"updateRule": null,
 | 
						|
			"deleteRule": null,
 | 
						|
			"options": {}
 | 
						|
		}`
 | 
						|
 | 
						|
		collection := &models.Collection{}
 | 
						|
		if err := json.Unmarshal([]byte(jsonData), &collection); err != nil {
 | 
						|
			return err
 | 
						|
		}
 | 
						|
 | 
						|
		return daos.New(db).SaveCollection(collection)
 | 
						|
	})
 | 
						|
}
 |