-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unifies SQLite and Postgres backend into a single docker image (#397)
* Unified postgres and sqlite connection in one container. * Improved logging. * Added macro invocation to prevent code doubling. * Added default features sqlite and postgresql. * Fixed clippy. * Removed unnecessary macros. * Install git. * Fixed build rs. * Fixed linter.
- Loading branch information
1 parent
3ceec62
commit d5e1607
Showing
31 changed files
with
152 additions
and
183 deletions.
There are no files selected for viewing
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
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
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,60 +1,32 @@ | ||
#[cfg(sqlite)] | ||
#[path = "schemas/sqlite/schema.rs"] | ||
pub mod schema; | ||
|
||
#[cfg(mysql)] | ||
#[path = "schemas/mysql/schema.rs"] | ||
pub mod schema; | ||
|
||
#[cfg(postgresql)] | ||
#[path = "schemas/postgresql/schema.rs"] | ||
pub mod schema; | ||
|
||
|
||
#[macro_export] | ||
#[cfg(sqlite)] | ||
macro_rules! import_database_connections { | ||
() => { | ||
use diesel::SqliteConnection; | ||
}; | ||
} | ||
|
||
#[macro_export] | ||
#[cfg(postgresql)] | ||
macro_rules! import_database_connections { | ||
() => { | ||
use diesel::PgConnection; | ||
}; | ||
#[derive(diesel::MultiConnection)] | ||
pub enum DBType { | ||
Postgresql(diesel::PgConnection), | ||
Sqlite(diesel::SqliteConnection), | ||
} | ||
|
||
#[macro_export] | ||
#[cfg(mysql)] | ||
macro_rules! import_database_connections { | ||
() => { | ||
use diesel::MysqlConnection; | ||
}; | ||
} | ||
|
||
|
||
#[macro_export] | ||
macro_rules! import_database_config{ | ||
()=>{ | ||
#[cfg(sqlite)] | ||
type DbConnection = SqliteConnection; | ||
#[cfg(sqlite)] | ||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations/sqlite"); | ||
|
||
|
||
#[cfg(postgresql)] | ||
pub type DbConnection = PgConnection; | ||
pub const SQLITE_MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations/sqlite"); | ||
|
||
|
||
#[cfg(postgresql)] | ||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations/postgres"); | ||
|
||
#[cfg(mysql)] | ||
type DbConnection = MysqlConnection; | ||
#[cfg(mysql)] | ||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations/mysql"); | ||
pub const POSTGRES_MIGRATIONS: EmbeddedMigrations = embed_migrations!("./migrations/postgres"); | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! execute_with_conn { | ||
($conn:expr, $diesel_func:expr) => { | ||
match $conn { | ||
DbConnection::Sqlite(conn) => { | ||
return $diesel_func(conn) | ||
}, | ||
DbConnection::Postgresql(conn) => { | ||
return $diesel_func(conn) | ||
}, | ||
} | ||
}; | ||
} |
Oops, something went wrong.