[#5618] added support to conditionally reapply migrations

This commit is contained in:
Gani Georgiev
2024-10-08 16:23:58 +03:00
parent ed1dc54f27
commit 646331bfa2
13 changed files with 320 additions and 207 deletions

View File

@@ -28,10 +28,6 @@ func Register(
func init() {
core.SystemMigrations.Register(func(txApp core.App) error {
if err := createLogsTable(txApp); err != nil {
return fmt.Errorf("_logs error: %w", err)
}
if err := createParamsTable(txApp); err != nil {
return fmt.Errorf("_params exec error: %w", err)
}
@@ -86,11 +82,6 @@ func init() {
return nil
}, func(txApp core.App) error {
_, err := txApp.AuxDB().DropTable("_logs").Execute()
if err != nil {
return err
}
tables := []string{
"users",
core.CollectionNameSuperusers,
@@ -124,24 +115,6 @@ func createParamsTable(txApp core.App) error {
return execErr
}
func createLogsTable(txApp core.App) error {
_, execErr := txApp.AuxDB().NewQuery(`
CREATE TABLE {{_logs}} (
[[id]] TEXT PRIMARY KEY DEFAULT ('r'||lower(hex(randomblob(7)))) NOT NULL,
[[level]] INTEGER DEFAULT 0 NOT NULL,
[[message]] TEXT DEFAULT "" NOT NULL,
[[data]] JSON DEFAULT "{}" NOT NULL,
[[created]] TEXT DEFAULT (strftime('%Y-%m-%d %H:%M:%fZ')) NOT NULL
);
CREATE INDEX idx_logs_level on {{_logs}} ([[level]]);
CREATE INDEX idx_logs_message on {{_logs}} ([[message]]);
CREATE INDEX idx_logs_created_hour on {{_logs}} (strftime('%Y-%m-%d %H:00:00', [[created]]));
`).Execute()
return execErr
}
func createMFAsCollection(txApp core.App) error {
col := core.NewBaseCollection(core.CollectionNameMFAs)
col.System = true