From c9fba9972af1ba22b318ca173569266faa4fcf54 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Mon, 27 Mar 2023 16:07:47 +0300 Subject: [PATCH] cleanup old remaining temp views --- migrations/1679986800_add_indexes_column.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/migrations/1679986800_add_indexes_column.go b/migrations/1679986800_add_indexes_column.go index 3d6aa96d..597a803e 100644 --- a/migrations/1679986800_add_indexes_column.go +++ b/migrations/1679986800_add_indexes_column.go @@ -18,6 +18,25 @@ func init() { AppMigrations.Register(func(db dbx.Builder) error { dao := daos.New(db) + // cleanup failed remaining/"dangling" temp views to prevent + // errors during the indexes upsert + // --- + tempViews := []string{} + viewsErr := db.Select("name"). + From("sqlite_schema"). + AndWhere(dbx.HashExp{"type": "view"}). + AndWhere(dbx.NewExp(`[[name]] LIKE '\_temp\_%' ESCAPE '\'`)). + Column(&tempViews) + if viewsErr != nil { + return viewsErr + } + for _, name := range tempViews { + if err := dao.DeleteView(name); err != nil { + return err + } + } + // --- + cols, err := dao.TableColumns("_collections") if err != nil { return err