WIP: migrations
This commit is contained in:
25
source/db/migrations/m_001_initial.d
Normal file
25
source/db/migrations/m_001_initial.d
Normal file
@@ -0,0 +1,25 @@
|
||||
module db.migrations.m_001_initial;
|
||||
|
||||
import db.migrations.migration;
|
||||
|
||||
Migration Initial = Migration(
|
||||
[
|
||||
`create table users(
|
||||
id uuid not null,
|
||||
name character varying(255),
|
||||
handle character varying(255),
|
||||
local boolean not null,
|
||||
ap_id character varying(255) not null,
|
||||
ap_privkey text,
|
||||
ap_pubkey text,
|
||||
ap_shared_inbox text,
|
||||
ap_inbox text,
|
||||
ap_outbox text,
|
||||
ap_followers_addr text,
|
||||
ap_following_addr text
|
||||
);`
|
||||
],
|
||||
[
|
||||
`drop table users;`
|
||||
],
|
||||
);
|
||||
31
source/db/migrations/migration.d
Normal file
31
source/db/migrations/migration.d
Normal file
@@ -0,0 +1,31 @@
|
||||
module db.migrations.migration;
|
||||
|
||||
import singletons;
|
||||
import db.migrations.m_001_initial;
|
||||
|
||||
struct Migration {
|
||||
string[] upStatements;
|
||||
string[] downStatements;
|
||||
|
||||
bool up() {
|
||||
int result;
|
||||
|
||||
foreach (string statement; upStatements)
|
||||
result |= Db.runUpdate(statement);
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
bool down() {
|
||||
int result;
|
||||
|
||||
foreach (string statement; downStatements)
|
||||
result |= Db.runUpdate(statement);
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
}
|
||||
|
||||
Migration[string] migrations = [
|
||||
"001_initial": Initial,
|
||||
];
|
||||
Reference in New Issue
Block a user