Skip to main content

toolu_orm_cli/migrate/
ddl.rs

1//! Dialect-aware DDL for the internal `_migrations` table.
2
3use toolu_orm_core::dialect::Dialect;
4
5/// DDL for the internal `_migrations` table (dialect-specific).
6#[must_use]
7pub fn migrations_table_ddl(dialect: Dialect) -> String {
8  match dialect {
9    Dialect::Sqlite => "CREATE TABLE IF NOT EXISTS _migrations (
10                id INTEGER PRIMARY KEY AUTOINCREMENT,
11                name TEXT NOT NULL UNIQUE,
12                hash TEXT NOT NULL DEFAULT '',
13                applied_at INTEGER NOT NULL DEFAULT (unixepoch())
14            );"
15      .to_owned(),
16    Dialect::Postgres => "CREATE TABLE IF NOT EXISTS _migrations (
17                id SERIAL PRIMARY KEY,
18                name TEXT NOT NULL UNIQUE,
19                hash TEXT NOT NULL DEFAULT '',
20                applied_at BIGINT NOT NULL DEFAULT extract(epoch from now())::bigint
21            );"
22      .to_owned(),
23  }
24}