added support for Model migrations

now we have a table core.migration and each model (User, Group, Item, ItemContent and a new Migration) have its own
row in the table with a version number

added to config:
db_make_migration_if_needed and db_stop_if_migration_fails (need description yet)
This commit is contained in:
2021-05-14 03:31:29 +02:00
parent 4df10de6b7
commit a94e09f0aa
16 changed files with 674 additions and 40 deletions

View File

@@ -137,6 +137,47 @@ return false;
}
bool User::do_migration(int & current_table_version)
{
bool ok = true;
ok = ok && morm::Model::do_migration(current_table_version, 1, this, &User::do_migration_to_1);
return ok;
}
bool User::do_migration_to_1()
{
const char * str = R"sql(
CREATE TABLE core."user" (
id serial,
login character varying(255),
password character varying(255),
email character varying(255),
notify integer,
pass_type integer,
pass_hash_salted boolean,
pass_encrypted bytea,
super_user boolean,
env text,
aenv text,
status integer,
locale_id integer,
time_zone_id integer,
has_pass boolean
);
)sql";
db_query(str);
return true; // IMPROVEME remove me in the future: this is only for a moment until we do migration on all our sites
}