File tree Expand file tree Collapse file tree 3 files changed +17
-29
lines changed
crates/database/src/migrations Expand file tree Collapse file tree 3 files changed +17
-29
lines changed Original file line number Diff line number Diff line change 11use rusqlite:: OptionalExtension ;
2- use v000_migration:: InitialMigration ;
3- use v001_task:: TaskMigration ;
42
53use crate :: { Database , Result } ;
64
7- mod v000_migration;
8- mod v001_task;
5+ mod v000_initial;
96
10- const MIGRATIONS : & [ & dyn Migration ] = & [ & InitialMigration , & TaskMigration ] ;
7+ const MIGRATIONS : & [ & dyn Migration ] = & [ & v000_initial :: InitialMigration ] ;
118
129trait Migration {
1310 fn sql ( & self ) -> & str ;
1411
1512 fn apply ( & self , db : & mut Database ) -> Result < ( ) > {
16- let sql = self . sql ( ) ;
17- let sql = format ! ( "BEGIN;\n \n {sql}\n \n COMMIT;\n " ) ;
18- db. connection . execute_batch ( & sql) ?;
13+ db. connection . execute_batch ( self . sql ( ) ) ?;
1914 Ok ( ( ) )
2015 }
2116
Original file line number Diff line number Diff line change 11use super :: Migration ;
22
3- /// The ID column of most of tables has to be globally unique,
4- /// because the application is intented to be used in a distributed way,
5- /// where the clients don't know about each other.
63const SQL : & str = r"
4+ BEGIN TRANSACTION;
5+
6+ CREATE TABLE migration_table (
7+ `id` INTEGER PRIMARY KEY,
8+ `sql` TEXT NOT NULL
9+ ) STRICT;
10+
11+
712CREATE TABLE IF NOT EXISTS task_table (
813 `id` BLOB PRIMARY KEY, -- UUID
914 `title` TEXT,
@@ -86,11 +91,15 @@ CREATE TABLE IF NOT EXISTS backend_config_table (
8691
8792CREATE INDEX IF NOT EXISTS task_tag_table_task_id_idx ON task_tag_table (task_id);
8893CREATE INDEX IF NOT EXISTS task_tag_table_tag_id_idx ON task_tag_table (tag_id);
94+
95+ ANALYZE;
96+
97+ COMMIT;
8998" ;
9099
91- pub ( super ) struct TaskMigration ;
100+ pub ( super ) struct InitialMigration ;
92101
93- impl Migration for TaskMigration {
102+ impl Migration for InitialMigration {
94103 fn sql ( & self ) -> & str {
95104 SQL
96105 }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments