mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-07 21:19:51 +00:00
chore: create migration snapshot
This commit is contained in:
parent
d588e14a58
commit
fe93334f86
@ -41,13 +41,13 @@ func NewCertificateService(certRepo certificateRepository) *CertificateService {
|
||||
|
||||
func (s *CertificateService) InitSchedule(ctx context.Context) error {
|
||||
app.GetScheduler().MustAdd("certificateExpireSoonNotify", "0 0 * * *", func() {
|
||||
certs, err := s.certRepo.ListExpireSoon(context.Background())
|
||||
certificates, err := s.certRepo.ListExpireSoon(context.Background())
|
||||
if err != nil {
|
||||
app.GetLogger().Error("failed to get certificates which expire soon", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
notification := buildExpireSoonNotification(certs)
|
||||
notification := buildExpireSoonNotification(certificates)
|
||||
if notification == nil {
|
||||
return
|
||||
}
|
||||
|
10
main.go
10
main.go
@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
_ "time/tzdata"
|
||||
@ -56,15 +56,13 @@ func main() {
|
||||
|
||||
app.OnTerminate().BindFunc(func(e *core.TerminateEvent) error {
|
||||
routes.Unregister()
|
||||
|
||||
log.Println("Exit!")
|
||||
|
||||
slog.Info("[CERTIMATE] Exit!")
|
||||
return e.Next()
|
||||
})
|
||||
|
||||
log.Printf("Visit the website: http://%s", flagHttp)
|
||||
slog.Info("[CERTIMATE] Visit the website: http://" + flagHttp)
|
||||
|
||||
if err := app.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
slog.Error("[CERTIMATE] Start failed.", "err", err)
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
superusers, err := app.FindCollectionByNameOrId(core.CollectionNameSuperusers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
record, _ := app.FindAuthRecordByEmail(core.CollectionNameSuperusers, "admin@certimate.fun")
|
||||
if record == nil {
|
||||
record := core.NewRecord(superusers)
|
||||
record.Set("email", "admin@certimate.fun")
|
||||
record.Set("password", "1234567890")
|
||||
return app.Save(record)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, func(app core.App) error {
|
||||
return nil
|
||||
})
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4szxr9x43tpj6np")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_Jx8TXzDCmw` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_kcKpgAZapk` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowNodeId` + "`" + `)"
|
||||
]
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(3, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2069360702",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "serialNumber",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(6, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2910474005",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "issuer",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(8, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text4164403445",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "keyAlgorithm",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(11, []byte(`{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2045248758",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "acmeAccountUrl",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4szxr9x43tpj6np")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": []
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("text2069360702")
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("text2910474005")
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("text4164403445")
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("text2045248758")
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("tovyif5ax6j62ur")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(10, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "zivdxh23",
|
||||
"maxSelect": 1,
|
||||
"name": "lastRunStatus",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"pending",
|
||||
"running",
|
||||
"succeeded",
|
||||
"failed",
|
||||
"canceled"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("tovyif5ax6j62ur")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(10, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "zivdxh23",
|
||||
"maxSelect": 1,
|
||||
"name": "lastRunStatus",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"pending",
|
||||
"running",
|
||||
"succeeded",
|
||||
"failed"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("qjp8lygssgwyqyz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "qldmh0tw",
|
||||
"maxSelect": 1,
|
||||
"name": "status",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"pending",
|
||||
"running",
|
||||
"succeeded",
|
||||
"failed",
|
||||
"canceled"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("qjp8lygssgwyqyz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "qldmh0tw",
|
||||
"maxSelect": 1,
|
||||
"name": "status",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"pending",
|
||||
"running",
|
||||
"succeeded",
|
||||
"failed"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4szxr9x43tpj6np")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_Jx8TXzDCmw` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_kcKpgAZapk` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowNodeId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_2cRXqNDyyp` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowRunId` + "`" + `)"
|
||||
]
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(15, []byte(`{
|
||||
"cascadeDelete": false,
|
||||
"collectionId": "qjp8lygssgwyqyz",
|
||||
"hidden": false,
|
||||
"id": "relation3917999135",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "workflowRunId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4szxr9x43tpj6np")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_Jx8TXzDCmw` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_kcKpgAZapk` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowNodeId` + "`" + `)"
|
||||
]
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("relation3917999135")
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("bqnxb95f2cooowp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_BYoQPsz4my` + "`" + ` ON ` + "`" + `workflow_output` + "`" + ` (` + "`" + `workflowId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_O9zxLETuxJ` + "`" + ` ON ` + "`" + `workflow_output` + "`" + ` (` + "`" + `runId` + "`" + `)"
|
||||
]
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"cascadeDelete": false,
|
||||
"collectionId": "qjp8lygssgwyqyz",
|
||||
"hidden": false,
|
||||
"id": "relation821863227",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "runId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("bqnxb95f2cooowp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": []
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("relation821863227")
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "hwy7m03o",
|
||||
"maxSelect": 1,
|
||||
"name": "provider",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"acmehttpreq",
|
||||
"aliyun",
|
||||
"aws",
|
||||
"azure",
|
||||
"baiducloud",
|
||||
"baotapanel",
|
||||
"byteplus",
|
||||
"cloudflare",
|
||||
"dogecloud",
|
||||
"godaddy",
|
||||
"huaweicloud",
|
||||
"k8s",
|
||||
"local",
|
||||
"namedotcom",
|
||||
"namesilo",
|
||||
"powerdns",
|
||||
"qiniu",
|
||||
"ssh",
|
||||
"tencentcloud",
|
||||
"ucloud",
|
||||
"volcengine",
|
||||
"webhook"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "hwy7m03o",
|
||||
"maxSelect": 1,
|
||||
"name": "provider",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"acmehttpreq",
|
||||
"aliyun",
|
||||
"aws",
|
||||
"azure",
|
||||
"baiducloud",
|
||||
"byteplus",
|
||||
"cloudflare",
|
||||
"dogecloud",
|
||||
"godaddy",
|
||||
"huaweicloud",
|
||||
"k8s",
|
||||
"local",
|
||||
"namedotcom",
|
||||
"namesilo",
|
||||
"powerdns",
|
||||
"qiniu",
|
||||
"ssh",
|
||||
"tencentcloud",
|
||||
"ucloud",
|
||||
"volcengine",
|
||||
"webhook"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("qjp8lygssgwyqyz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
|
||||
"cascadeDelete": true,
|
||||
"collectionId": "tovyif5ax6j62ur",
|
||||
"hidden": false,
|
||||
"id": "m8xfsyyy",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "workflowId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("qjp8lygssgwyqyz")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
|
||||
"cascadeDelete": false,
|
||||
"collectionId": "tovyif5ax6j62ur",
|
||||
"hidden": false,
|
||||
"id": "m8xfsyyy",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "workflowId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("bqnxb95f2cooowp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
|
||||
"cascadeDelete": true,
|
||||
"collectionId": "tovyif5ax6j62ur",
|
||||
"hidden": false,
|
||||
"id": "jka88auc",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "workflowId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"cascadeDelete": true,
|
||||
"collectionId": "qjp8lygssgwyqyz",
|
||||
"hidden": false,
|
||||
"id": "relation821863227",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "runId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("bqnxb95f2cooowp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(1, []byte(`{
|
||||
"cascadeDelete": false,
|
||||
"collectionId": "tovyif5ax6j62ur",
|
||||
"hidden": false,
|
||||
"id": "jka88auc",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "workflowId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"cascadeDelete": false,
|
||||
"collectionId": "qjp8lygssgwyqyz",
|
||||
"hidden": false,
|
||||
"id": "relation821863227",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "runId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": [
|
||||
"CREATE INDEX `+"`"+`idx_wkoST0j`+"`"+` ON `+"`"+`access`+"`"+` (`+"`"+`name`+"`"+`)",
|
||||
"CREATE INDEX `+"`"+`idx_frh0JT1Aqx`+"`"+` ON `+"`"+`access`+"`"+` (`+"`"+`provider`+"`"+`)"
|
||||
]
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "hwy7m03o",
|
||||
"maxSelect": 1,
|
||||
"name": "provider",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"1panel",
|
||||
"acmehttpreq",
|
||||
"akamai",
|
||||
"aliyun",
|
||||
"aws",
|
||||
"azure",
|
||||
"baiducloud",
|
||||
"baishan",
|
||||
"baotapanel",
|
||||
"byteplus",
|
||||
"cachefly",
|
||||
"cdnfly",
|
||||
"cloudflare",
|
||||
"cloudns",
|
||||
"cmcccloud",
|
||||
"ctcccloud",
|
||||
"cucccloud",
|
||||
"dogecloud",
|
||||
"edgio",
|
||||
"fastly",
|
||||
"gname",
|
||||
"gcore",
|
||||
"godaddy",
|
||||
"goedge",
|
||||
"huaweicloud",
|
||||
"k8s",
|
||||
"local",
|
||||
"namedotcom",
|
||||
"namesilo",
|
||||
"ns1",
|
||||
"powerdns",
|
||||
"qiniu",
|
||||
"rainyun",
|
||||
"safeline",
|
||||
"ssh",
|
||||
"tencentcloud",
|
||||
"ucloud",
|
||||
"volcengine",
|
||||
"webhook",
|
||||
"westcn"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove field
|
||||
collection.Fields.RemoveById("hsxcnlvd")
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update collection data
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"indexes": [
|
||||
"CREATE INDEX `+"`"+`idx_wkoST0j`+"`"+` ON `+"`"+`access`+"`"+` (`+"`"+`name`+"`"+`)"
|
||||
]
|
||||
}`), &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// update field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "hwy7m03o",
|
||||
"maxSelect": 1,
|
||||
"name": "provider",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"acmehttpreq",
|
||||
"aliyun",
|
||||
"aws",
|
||||
"azure",
|
||||
"baiducloud",
|
||||
"baotapanel",
|
||||
"byteplus",
|
||||
"cloudflare",
|
||||
"dogecloud",
|
||||
"godaddy",
|
||||
"huaweicloud",
|
||||
"k8s",
|
||||
"local",
|
||||
"namedotcom",
|
||||
"namesilo",
|
||||
"powerdns",
|
||||
"qiniu",
|
||||
"ssh",
|
||||
"tencentcloud",
|
||||
"ucloud",
|
||||
"volcengine",
|
||||
"webhook"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add field
|
||||
if err := collection.Fields.AddMarshaledJSONAt(4, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "hsxcnlvd",
|
||||
"maxSelect": 1,
|
||||
"name": "usage",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"apply",
|
||||
"deploy",
|
||||
"all"
|
||||
]
|
||||
}`)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collection)
|
||||
})
|
||||
}
|
@ -1,12 +1,116 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
x509 "crypto/x509"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/certs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
slog.Info("[CERTIMATE] migration: ready ...")
|
||||
|
||||
// backup collection records
|
||||
collectionRecords := make([]*core.Record, 0)
|
||||
collections, err := app.FindAllCollections(core.CollectionTypeBase)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, collection := range collections {
|
||||
switch collection.Name {
|
||||
case "acme_accounts", "access", "certificate", "workflow", "settings":
|
||||
{
|
||||
records, err := app.FindAllRecords(collection)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
collectionRecords = append(collectionRecords, records...)
|
||||
|
||||
slog.Info("[CERTIMATE] migration: collection '" + collection.Name + "' backed up")
|
||||
|
||||
if collection.Name == "access" {
|
||||
collection.Fields.RemoveByName("usage")
|
||||
|
||||
for i, field := range collection.Fields {
|
||||
if field.GetName() == "provider" {
|
||||
collection.Fields.AddMarshaledJSONAt(i+1, []byte(`{
|
||||
"hidden": false,
|
||||
"id": "hwy7m03o",
|
||||
"maxSelect": 1,
|
||||
"name": "provider",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"1panel",
|
||||
"acmehttpreq",
|
||||
"akamai",
|
||||
"aliyun",
|
||||
"aws",
|
||||
"azure",
|
||||
"baiducloud",
|
||||
"baishan",
|
||||
"baotapanel",
|
||||
"byteplus",
|
||||
"cachefly",
|
||||
"cdnfly",
|
||||
"cloudflare",
|
||||
"cloudns",
|
||||
"cmcccloud",
|
||||
"ctcccloud",
|
||||
"cucccloud",
|
||||
"dogecloud",
|
||||
"edgio",
|
||||
"fastly",
|
||||
"gname",
|
||||
"gcore",
|
||||
"godaddy",
|
||||
"goedge",
|
||||
"huaweicloud",
|
||||
"k8s",
|
||||
"local",
|
||||
"namedotcom",
|
||||
"namesilo",
|
||||
"ns1",
|
||||
"powerdns",
|
||||
"qiniu",
|
||||
"rainyun",
|
||||
"safeline",
|
||||
"ssh",
|
||||
"tencentcloud",
|
||||
"ucloud",
|
||||
"volcengine",
|
||||
"webhook",
|
||||
"westcn"
|
||||
]
|
||||
}`))
|
||||
}
|
||||
}
|
||||
|
||||
err := app.Save(collection)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case "domains", "deployments", "access_groups":
|
||||
{
|
||||
app.Delete(collection)
|
||||
|
||||
slog.Info("[CERTIMATE] migration: collection '" + collection.Name + "' truncated")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// migrate
|
||||
jsonData := `[
|
||||
{
|
||||
"createRule": null,
|
||||
@ -50,27 +154,46 @@ func init() {
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"1panel",
|
||||
"acmehttpreq",
|
||||
"akamai",
|
||||
"aliyun",
|
||||
"aws",
|
||||
"azure",
|
||||
"baiducloud",
|
||||
"baishan",
|
||||
"baotapanel",
|
||||
"byteplus",
|
||||
"cachefly",
|
||||
"cdnfly",
|
||||
"cloudflare",
|
||||
"cloudns",
|
||||
"cmcccloud",
|
||||
"ctcccloud",
|
||||
"cucccloud",
|
||||
"dogecloud",
|
||||
"edgio",
|
||||
"fastly",
|
||||
"gname",
|
||||
"gcore",
|
||||
"godaddy",
|
||||
"goedge",
|
||||
"huaweicloud",
|
||||
"k8s",
|
||||
"local",
|
||||
"namedotcom",
|
||||
"namesilo",
|
||||
"ns1",
|
||||
"powerdns",
|
||||
"qiniu",
|
||||
"rainyun",
|
||||
"safeline",
|
||||
"ssh",
|
||||
"tencentcloud",
|
||||
"ucloud",
|
||||
"volcengine",
|
||||
"webhook"
|
||||
"webhook",
|
||||
"westcn"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -83,21 +206,6 @@ func init() {
|
||||
"system": false,
|
||||
"type": "json"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "hsxcnlvd",
|
||||
"maxSelect": 1,
|
||||
"name": "usage",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "select",
|
||||
"values": [
|
||||
"apply",
|
||||
"deploy",
|
||||
"all"
|
||||
]
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "lr33hiwg",
|
||||
@ -132,7 +240,8 @@ func init() {
|
||||
],
|
||||
"id": "4yzbv8urny5ja1e",
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_wkoST0j` + "`" + ` ON ` + "`" + `access` + "`" + ` (` + "`" + `name` + "`" + `)"
|
||||
"CREATE INDEX ` + "`" + `idx_wkoST0j` + "`" + ` ON ` + "`" + `access` + "`" + ` (` + "`" + `name` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_frh0JT1Aqx` + "`" + ` ON ` + "`" + `access` + "`" + ` (` + "`" + `provider` + "`" + `)"
|
||||
],
|
||||
"listRule": null,
|
||||
"name": "access",
|
||||
@ -450,7 +559,8 @@ func init() {
|
||||
"pending",
|
||||
"running",
|
||||
"succeeded",
|
||||
"failed"
|
||||
"failed",
|
||||
"canceled"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -513,7 +623,7 @@ func init() {
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"cascadeDelete": false,
|
||||
"cascadeDelete": true,
|
||||
"collectionId": "tovyif5ax6j62ur",
|
||||
"hidden": false,
|
||||
"id": "jka88auc",
|
||||
@ -525,6 +635,19 @@ func init() {
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
},
|
||||
{
|
||||
"cascadeDelete": true,
|
||||
"collectionId": "qjp8lygssgwyqyz",
|
||||
"hidden": false,
|
||||
"id": "relation821863227",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "runId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
@ -590,7 +713,10 @@ func init() {
|
||||
}
|
||||
],
|
||||
"id": "bqnxb95f2cooowp",
|
||||
"indexes": [],
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_BYoQPsz4my` + "`" + ` ON ` + "`" + `workflow_output` + "`" + ` (` + "`" + `workflowId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_O9zxLETuxJ` + "`" + ` ON ` + "`" + `workflow_output` + "`" + ` (` + "`" + `runId` + "`" + `)"
|
||||
],
|
||||
"listRule": null,
|
||||
"name": "workflow_output",
|
||||
"system": false,
|
||||
@ -644,6 +770,20 @@ func init() {
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2069360702",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "serialNumber",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
@ -672,6 +812,20 @@ func init() {
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2910474005",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "issuer",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
@ -686,6 +840,20 @@ func init() {
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text4164403445",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "keyAlgorithm",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"hidden": false,
|
||||
"id": "v40aqzpd",
|
||||
@ -708,6 +876,20 @@ func init() {
|
||||
"system": false,
|
||||
"type": "date"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
"id": "text2045248758",
|
||||
"max": 0,
|
||||
"min": 0,
|
||||
"name": "acmeAccountUrl",
|
||||
"pattern": "",
|
||||
"presentable": false,
|
||||
"primaryKey": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"exceptDomains": null,
|
||||
"hidden": false,
|
||||
@ -743,6 +925,19 @@ func init() {
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
},
|
||||
{
|
||||
"cascadeDelete": false,
|
||||
"collectionId": "qjp8lygssgwyqyz",
|
||||
"hidden": false,
|
||||
"id": "relation3917999135",
|
||||
"maxSelect": 1,
|
||||
"minSelect": 0,
|
||||
"name": "workflowRunId",
|
||||
"presentable": false,
|
||||
"required": false,
|
||||
"system": false,
|
||||
"type": "relation"
|
||||
},
|
||||
{
|
||||
"autogeneratePattern": "",
|
||||
"hidden": false,
|
||||
@ -803,7 +998,11 @@ func init() {
|
||||
}
|
||||
],
|
||||
"id": "4szxr9x43tpj6np",
|
||||
"indexes": [],
|
||||
"indexes": [
|
||||
"CREATE INDEX ` + "`" + `idx_Jx8TXzDCmw` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_kcKpgAZapk` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowNodeId` + "`" + `)",
|
||||
"CREATE INDEX ` + "`" + `idx_2cRXqNDyyp` + "`" + ` ON ` + "`" + `certificate` + "`" + ` (` + "`" + `workflowRunId` + "`" + `)"
|
||||
],
|
||||
"listRule": null,
|
||||
"name": "certificate",
|
||||
"system": false,
|
||||
@ -830,7 +1029,7 @@ func init() {
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"cascadeDelete": false,
|
||||
"cascadeDelete": true,
|
||||
"collectionId": "tovyif5ax6j62ur",
|
||||
"hidden": false,
|
||||
"id": "m8xfsyyy",
|
||||
@ -855,7 +1054,8 @@ func init() {
|
||||
"pending",
|
||||
"running",
|
||||
"succeeded",
|
||||
"failed"
|
||||
"failed",
|
||||
"canceled"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -1517,8 +1717,84 @@ func init() {
|
||||
"viewRule": "@request.auth.id != '' && recordRef = @request.auth.id && collectionRef = @request.auth.collectionId"
|
||||
}
|
||||
]`
|
||||
err = app.ImportCollectionsByMarshaledJSON([]byte(jsonData), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.ImportCollectionsByMarshaledJSON([]byte(jsonData), false)
|
||||
slog.Info("[CERTIMATE] migration: collections imported")
|
||||
|
||||
// restore records
|
||||
for _, record := range collectionRecords {
|
||||
changed := false
|
||||
|
||||
switch record.Collection().Name {
|
||||
case "access":
|
||||
{
|
||||
if record.GetString("provider") == "tencent" {
|
||||
record.Set("provider", "tencentcloud")
|
||||
changed = true
|
||||
} else if record.GetString("provider") == "pdns" {
|
||||
record.Set("provider", "powerdns")
|
||||
changed = true
|
||||
} else if record.GetString("provider") == "httpreq" {
|
||||
record.Set("provider", "acmehttpreq")
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
case "certificate":
|
||||
{
|
||||
if record.GetString("issuer") == "" {
|
||||
cert, _ := certs.ParseCertificateFromPEM(record.GetString("certificate"))
|
||||
if cert != nil {
|
||||
record.Set("issuer", strings.Join(cert.Issuer.Organization, ";"))
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if record.GetString("serialNumber") == "" {
|
||||
cert, _ := certs.ParseCertificateFromPEM(record.GetString("certificate"))
|
||||
if cert != nil {
|
||||
record.Set("serialNumber", strings.ToUpper(cert.SerialNumber.Text(16)))
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if record.GetString("keyAlgorithm") == "" {
|
||||
cert, _ := certs.ParseCertificateFromPEM(record.GetString("certificate"))
|
||||
if cert != nil {
|
||||
switch cert.SignatureAlgorithm {
|
||||
case x509.SHA256WithRSA, x509.SHA256WithRSAPSS:
|
||||
record.Set("keyAlgorithm", "RSA2048")
|
||||
case x509.SHA384WithRSA, x509.SHA384WithRSAPSS:
|
||||
record.Set("keyAlgorithm", "RSA3072")
|
||||
case x509.SHA512WithRSA, x509.SHA512WithRSAPSS:
|
||||
record.Set("keyAlgorithm", "RSA4096")
|
||||
case x509.ECDSAWithSHA256:
|
||||
record.Set("keyAlgorithm", "EC256")
|
||||
case x509.ECDSAWithSHA384:
|
||||
record.Set("keyAlgorithm", "EC384")
|
||||
case x509.ECDSAWithSHA512:
|
||||
record.Set("keyAlgorithm", "EC512")
|
||||
}
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if changed {
|
||||
err = app.Save(record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
slog.Info("[CERTIMATE] migration: collection '" + record.Collection().Name + "' record #" + record.Id + " updated")
|
||||
}
|
||||
}
|
||||
|
||||
slog.Info("[CERTIMATE] migration: done")
|
||||
|
||||
return nil
|
||||
}, func(app core.App) error {
|
||||
return nil
|
||||
})
|
44
migrations/1739462401_superusers_initial.go
Normal file
44
migrations/1739462401_superusers_initial.go
Normal file
@ -0,0 +1,44 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
superusers, err := app.FindCollectionByNameOrId(core.CollectionNameSuperusers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
records, err := app.FindAllRecords(superusers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(records) == 0 {
|
||||
envUsername := strings.TrimSpace(os.Getenv("CERTIMATE_ADMIN_USERNAME"))
|
||||
if envUsername == "" {
|
||||
envUsername = "admin@certimate.fun"
|
||||
}
|
||||
|
||||
envPassword := strings.TrimSpace(os.Getenv("CERTIMATE_ADMIN_PASSWORD"))
|
||||
if envPassword == "" {
|
||||
envPassword = "1234567890"
|
||||
}
|
||||
|
||||
record := core.NewRecord(superusers)
|
||||
record.Set("email", envUsername)
|
||||
record.Set("password", envPassword)
|
||||
return app.Save(record)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, func(app core.App) error {
|
||||
return nil
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user