+15 -2 +/-3 browse
1 | diff --git a/core/build.rs b/core/build.rs |
2 | index 99aff85..44e41d2 100644 |
3 | --- a/core/build.rs |
4 | +++ b/core/build.rs |
5 | @@ -62,7 +62,7 @@ fn main() { |
6 | String::from_utf8_lossy(&output.stderr) |
7 | ); |
8 | } |
9 | - make_migrations("migrations", MIGRATION_RS, &mut output.stdout); |
10 | + let user_version: i32 = make_migrations("migrations", MIGRATION_RS, &mut output.stdout); |
11 | let mut verify = Command::new(std::env::var("SQLITE_BIN").unwrap_or("sqlite3".into())) |
12 | .stdin(Stdio::piped()) |
13 | .stdout(Stdio::piped()) |
14 | @@ -87,4 +87,9 @@ fn main() { |
15 | } |
16 | let mut file = std::fs::File::create("./src/schema.sql").unwrap(); |
17 | file.write_all(&output.stdout).unwrap(); |
18 | + file.write_all( |
19 | + &format!("\n\n-- Set current schema version.\n\nPRAGMA user_version = {user_version};\n") |
20 | + .as_bytes(), |
21 | + ) |
22 | + .unwrap(); |
23 | } |
24 | diff --git a/core/make_migrations.rs b/core/make_migrations.rs |
25 | index 4b4acbe..91f3f2e 100644 |
26 | --- a/core/make_migrations.rs |
27 | +++ b/core/make_migrations.rs |
28 | @@ -25,11 +25,13 @@ use std::{fs::read_dir, io::Write, path::Path}; |
29 | /// |
30 | /// If a migration is a data migration (not a CREATE, DROP or ALTER statement) it is appended to |
31 | /// the schema file. |
32 | + /// |
33 | + /// Returns the current `user_version` PRAGMA value. |
34 | pub fn make_migrations<M: AsRef<Path>, O: AsRef<Path>>( |
35 | migrations_path: M, |
36 | output_file: O, |
37 | schema_file: &mut Vec<u8>, |
38 | - ) { |
39 | + ) -> i32 { |
40 | let migrations_folder_path = migrations_path.as_ref(); |
41 | let output_file_path = output_file.as_ref(); |
42 | |
43 | @@ -104,4 +106,5 @@ pub fn make_migrations<M: AsRef<Path>, O: AsRef<Path>>( |
44 | } |
45 | migr_rs.write_all(b"]").unwrap(); |
46 | migr_rs.flush().unwrap(); |
47 | + paths.len() as i32 |
48 | } |
49 | diff --git a/core/src/schema.sql b/core/src/schema.sql |
50 | index ba839cb..52e6d34 100644 |
51 | --- a/core/src/schema.sql |
52 | +++ b/core/src/schema.sql |
53 | @@ -650,3 +650,8 @@ INSERT OR REPLACE INTO settings_json_schema(id, value) VALUES('MimeRejectSetting |
54 | } |
55 | } |
56 | }'); |
57 | + |
58 | + |
59 | + -- Set current schema version. |
60 | + |
61 | + PRAGMA user_version = 7; |