diff options
author | Frédéric Mangano-Tarumi <fmang@mg0.fr> | 2020-02-22 22:31:26 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2020-02-27 16:44:36 +0100 |
commit | a8a1f74a9207339bf707bb09e8dba7b2c67abb5b (patch) | |
tree | e8fa6de61abc49cb8710e283b7f6661e96add849 /aurweb | |
parent | 7188743fc3b1a9c1f5f65e323a6502d018bd95d5 (diff) | |
download | aur-a8a1f74a9207339bf707bb09e8dba7b2c67abb5b.tar.gz aur-a8a1f74a9207339bf707bb09e8dba7b2c67abb5b.tar.xz |
Set up Alembic for database migrations
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'aurweb')
-rw-r--r-- | aurweb/initdb.py | 9 | ||||
-rw-r--r-- | aurweb/schema.py | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/aurweb/initdb.py b/aurweb/initdb.py index e3e96503..c02fb961 100644 --- a/aurweb/initdb.py +++ b/aurweb/initdb.py @@ -1,6 +1,8 @@ import aurweb.db import aurweb.schema +import alembic.command +import alembic.config import argparse import sqlalchemy @@ -31,10 +33,17 @@ def feed_initial_data(conn): def run(args): + # Ensure Alembic is fine before we do the real work, in order not to fail at + # the last step and leave the database in an inconsistent state. The + # configuration is loaded lazily, so we query it to force its loading. + alembic_config = alembic.config.Config('alembic.ini') + alembic_config.get_main_option('script_location') + engine = sqlalchemy.create_engine(aurweb.db.get_sqlalchemy_url(), echo=(args.verbose >= 1)) aurweb.schema.metadata.create_all(engine) feed_initial_data(engine.connect()) + alembic.command.stamp(alembic_config, 'head') if __name__ == '__main__': diff --git a/aurweb/schema.py b/aurweb/schema.py index b1261e86..fde6512f 100644 --- a/aurweb/schema.py +++ b/aurweb/schema.py @@ -1,3 +1,11 @@ +""" +Schema of aurweb's database. + +Changes here should always be accompanied by an Alembic migration, which can be +usually be automatically generated. See `migrations/README` for details. +""" + + from sqlalchemy import CHAR, Column, ForeignKey, Index, MetaData, String, TIMESTAMP, Table, Text, text from sqlalchemy.dialects.mysql import BIGINT, DECIMAL, INTEGER, TINYINT from sqlalchemy.ext.compiler import compiles |