Open the database with options suitable for the migration inserts. This is not a safe mode of operation for normal processing, use only for bulk inserts with a close afterwards.
(path string)
| 100 | // is not a safe mode of operation for normal processing, use only for bulk |
| 101 | // inserts with a close afterwards. |
| 102 | func OpenForMigration(path string) (*DB, error) { |
| 103 | pragmas := []string{ |
| 104 | "journal_mode = OFF", |
| 105 | "foreign_keys = 0", |
| 106 | "synchronous = 0", |
| 107 | "locking_mode = EXCLUSIVE", |
| 108 | fmt.Sprintf("application_id = %d", applicationIDMain), |
| 109 | } |
| 110 | schemas := []string{ |
| 111 | "sql/schema/common/*", |
| 112 | "sql/schema/main/*", |
| 113 | } |
| 114 | migrations := []string{ |
| 115 | "sql/migrations/common/*", |
| 116 | "sql/migrations/main/*", |
| 117 | } |
| 118 | |
| 119 | _ = os.MkdirAll(path, 0o700) |
| 120 | initTmpDir(path) |
| 121 | |
| 122 | mainPath := filepath.Join(path, "main.db") |
| 123 | mainBase, err := openBase(mainPath, 1, pragmas, schemas, migrations) |
| 124 | if err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | |
| 128 | db := &DB{ |
| 129 | pathBase: path, |
| 130 | baseDB: mainBase, |
| 131 | folderDBs: make(map[string]*folderDB), |
| 132 | folderDBOpener: openFolderDBForMigration, |
| 133 | } |
| 134 | |
| 135 | if err := db.cleanDroppedFolders(); err != nil { |
| 136 | slog.Warn("Failed to clean dropped folders", slogutil.Error(err)) |
| 137 | } |
| 138 | |
| 139 | return db, nil |
| 140 | } |
| 141 | |
| 142 | func (s *DB) Close() error { |
| 143 | s.folderDBsMut.Lock() |
no test coverage detected