feat: inheritance for migration table

This commit is contained in:
2025-02-16 13:56:10 +00:00
parent c3cdf9858a
commit f3bbbeb12d
2 changed files with 59 additions and 32 deletions

View File

@@ -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();
}