feat: inheritance for migration table
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
use postgres::Client;
|
||||
|
||||
pub fn init_db(client: &mut Client) {
|
||||
client.batch_execute("
|
||||
CREATE SCHEMA IF NOT EXISTS hectic;
|
||||
CREATE TABLE IF NOT EXISTS hectic.migration (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT UNIQUE NOT NULL,
|
||||
applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
").unwrap();
|
||||
pub fn init_db(client: &mut Client, inherits: &[String]) {
|
||||
let inherits_clause = if !inherits.is_empty() {
|
||||
format!(" INHERITS ({})", inherits.join(", "))
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
client .batch_execute(&format!("
|
||||
CREATE SCHEMA IF NOT EXISTS hectic;
|
||||
CREATE TABLE IF NOT EXISTS hectic.migration (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT UNIQUE NOT NULL,
|
||||
applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
){}
|
||||
", inherits_clause)).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user