Skip to content

Commit 248fe01

Browse files
committed
fixing save remote server, timestamptz for postgres, updating nav bar on
sync
1 parent e5ee442 commit 248fe01

File tree

4 files changed

+79
-7
lines changed

4 files changed

+79
-7
lines changed

src-tauri/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::mysql::actually_sync_databases_mysql;
66
mod postgres;
77
use crate::postgres::actually_sync_databases_postgres;
88
mod migrations;
9-
use crate::migrations::{SQLITE_MIGRATIONS, MYSQL_PG_MIGRATIONS};
9+
use crate::migrations::{SQLITE_MIGRATIONS, MYSQL_MIGRATIONS, PG_MIGRATIONS};
1010

1111
use tauri::{
1212
State,
@@ -134,7 +134,7 @@ async fn sync_databases(db_instances: State<'_, DbInstances>) -> Result<(), Vec<
134134
.ssl_mode(MySqlSslMode::Required);
135135
let e_conn: Result<MySqlPool, String> = run_migrations_and_get_pool(
136136
conn_options,
137-
MYSQL_PG_MIGRATIONS.clone(),
137+
MYSQL_MIGRATIONS.clone(),
138138
auto_sync_time,
139139
).await;
140140
info!("e_conn returned");
@@ -165,7 +165,7 @@ async fn sync_databases(db_instances: State<'_, DbInstances>) -> Result<(), Vec<
165165
.ssl_mode(PgSslMode::VerifyFull);
166166
let e_conn: Result<PgPool, String> = run_migrations_and_get_pool(
167167
conn_options,
168-
MYSQL_PG_MIGRATIONS.clone(),
168+
PG_MIGRATIONS.clone(),
169169
auto_sync_time,
170170
).await;
171171
match e_conn {
@@ -241,7 +241,7 @@ async fn check_database(db_instances: State<'_, DbInstances>, db_id: &str) -> Re
241241
.ssl_mode(MySqlSslMode::Required);
242242
let conn: MySqlPool = run_migrations_and_get_pool(
243243
conn_options,
244-
MYSQL_PG_MIGRATIONS.clone(),
244+
MYSQL_MIGRATIONS.clone(),
245245
auto_sync_time,
246246
).await?;
247247
// let conn = MySqlPool::connect_with(conn_options).await.map_err(|e| e.to_string())?;
@@ -259,7 +259,7 @@ async fn check_database(db_instances: State<'_, DbInstances>, db_id: &str) -> Re
259259
.ssl_mode(PgSslMode::VerifyFull);
260260
let conn: PgPool = run_migrations_and_get_pool(
261261
conn_options,
262-
MYSQL_PG_MIGRATIONS.clone(),
262+
PG_MIGRATIONS.clone(),
263263
auto_sync_time,
264264
).await?;
265265
// let conn = PgPool::connect_with(conn_options).await.map_err(|e| e.to_string())?;

src-tauri/src/migrations.rs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ END;
168168
},
169169
]);
170170

171-
pub static ref MYSQL_PG_MIGRATIONS: MigrationList = MigrationList(vec![
171+
pub static ref MYSQL_MIGRATIONS: MigrationList = MigrationList(vec![
172172
Migration {
173173
version: 1,
174174
description: "create_initial_tables",
@@ -221,6 +221,72 @@ CHECK (trash IN (0, 1));
221221
CREATE TABLE IF NOT EXISTS deleted (
222222
id VARCHAR(32) PRIMARY KEY
223223
);
224+
",
225+
},
226+
]);
227+
228+
pub static ref PG_MIGRATIONS: MigrationList = MigrationList(vec![
229+
Migration {
230+
version: 1,
231+
description: "create_initial_tables",
232+
kind: MigrationKind::Up,
233+
sql: "
234+
CREATE TABLE IF NOT EXISTS books (
235+
id VARCHAR(32) PRIMARY KEY,
236+
name TEXT,
237+
modified TIMESTAMP NOT NULL
238+
);
239+
CREATE TABLE IF NOT EXISTS documents (
240+
id VARCHAR(32) PRIMARY KEY,
241+
book VARCHAR(32) NOT NULL,
242+
name TEXT,
243+
content TEXT,
244+
syntax TEXT NOT NULL,
245+
modified TIMESTAMP NOT NULL,
246+
FOREIGN KEY (book)
247+
REFERENCES books(id)
248+
ON DELETE CASCADE
249+
ON UPDATE CASCADE
250+
);
251+
",
252+
},
253+
Migration {
254+
version: 3,
255+
description: "add_icons_to_books_and_documents",
256+
kind: MigrationKind::Up,
257+
sql: "
258+
ALTER TABLE books ADD COLUMN icon TEXT;
259+
ALTER TABLE books ADD COLUMN icon_color TEXT;
260+
ALTER TABLE documents ADD COLUMN icon TEXT;
261+
ALTER TABLE documents ADD COLUMN icon_color TEXT;
262+
",
263+
},
264+
Migration {
265+
version: 4,
266+
description: "trash",
267+
kind: MigrationKind::Up,
268+
sql: "
269+
ALTER TABLE books ADD COLUMN trash INTEGER NOT NULL DEFAULT 0
270+
CHECK (trash IN (0, 1));
271+
",
272+
},
273+
Migration {
274+
version: 5,
275+
description: "permanently_deleted",
276+
kind: MigrationKind::Up,
277+
sql: "
278+
CREATE TABLE IF NOT EXISTS deleted (
279+
id VARCHAR(32) PRIMARY KEY
280+
);
281+
",
282+
},
283+
Migration {
284+
version: 6,
285+
description: "utc_timestamp",
286+
kind: MigrationKind::Up,
287+
sql: "
288+
ALTER TABLE books ALTER COLUMN modified TYPE TIMESTAMPTZ;
289+
ALTER TABLE documents ALTER COLUMN modified TYPE TIMESTAMPTZ;
224290
",
225291
},
226292
]);

src/App.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function App() {
6666
color: "green",
6767
autoClose: true,
6868
});
69+
setReloadNav(!reloadNav);
6970
} catch(e) {
7071
console.warn("sync_databases failed", e);
7172
notifications.update({
@@ -76,6 +77,11 @@ function App() {
7677
autoClose: false,
7778
})
7879
setAutoSync(false);
80+
const db = await Database.load(__LOCAL_DB);
81+
await db.execute(
82+
"UPDATE settings SET value = 'false' WHERE key = 'auto_sync'",
83+
[]
84+
);
7985
}
8086
}
8187
go();

src/Settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function Settings({
144144
try {
145145
const db = await Database.load(__LOCAL_DB);
146146
await db.execute(
147-
"UPDATE remote_servers (host, port, db, user, password, db_type) SET ($1, $2, $3, $4, $5, $6) WHERE id = $7",
147+
"UPDATE remote_servers SET host = $1, port = $2, db = $3, user = $4, password = $5, db_type = $6 WHERE id = $7",
148148
[s.host, s.port, s.db, s.user, s.password, s.dbType, s.id]
149149
);
150150
actuallyReload();

0 commit comments

Comments
 (0)