-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
85 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use crate::utils::fs::get_db_path; | ||
use deadpool_sqlite::rusqlite::{Connection as AppConnection, Error}; | ||
use include_dir::{include_dir, Dir}; | ||
use lazy_static::lazy_static; | ||
use rusqlite_migration::Migrations; | ||
use tracing::error; | ||
|
||
static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/src/database/migrations"); | ||
|
||
// Define migrations. These are applied atomically. | ||
lazy_static! { | ||
static ref MIGRATIONS: Migrations<'static> = | ||
Migrations::from_directory(&MIGRATIONS_DIR).unwrap(); | ||
} | ||
|
||
/// Initializes the database connection, creating the .sqlite file if needed, and upgrading the database | ||
/// if it's out of date. | ||
pub fn initialize_database() -> Result<AppConnection, Error> { | ||
let db_path = get_db_path(); | ||
let mut db = AppConnection::open(db_path)?; | ||
|
||
let _ = MIGRATIONS.to_latest(&mut db).map_err(|e| { | ||
error!("Error applying migrations: {:?}", e); | ||
}); | ||
|
||
Ok(db) | ||
} |
10 changes: 10 additions & 0 deletions
10
src-tauri/src/database/migrations/01-initial-schema/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE connections | ||
( | ||
id TEXT NOT NULL, | ||
dialect VARCHAR(255) NOT NULL, | ||
mode VARCHAR(255) NOT NULL, | ||
credentials VARCHAR(255) NOT NULL, | ||
SCHEMA VARCHAR(255) NOT NULL, | ||
NAME VARCHAR(255) NOT NULL, | ||
color VARCHAR(255) NOT NULL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod init; | ||
pub mod queries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters