# HG changeset patch # User Mads Kiilerich # Date 1592580276 -7200 # Node ID e1f233b069b044b5eff1ec931ed864aa73f689c8 # Parent 7b0aafc6b7cac0f4ae766287b14d744f3add1bbd db: refactor to clarify that we always invoke SA create_all with checkfirst=False create_all(checkfirst=True) would skip creating tables that already exist, potentially leaving them with wrong schema. We are strict and want a successful create_all to leave all the tables in a fully known state. We thus want it to fail if any tables already are present. Existing tables should not silently be accepted. diff -r 7b0aafc6b7ca -r e1f233b069b0 kallithea/bin/kallithea_cli_db.py --- a/kallithea/bin/kallithea_cli_db.py Mon Jun 15 17:27:19 2020 +0200 +++ b/kallithea/bin/kallithea_cli_db.py Fri Jun 19 17:24:36 2020 +0200 @@ -57,7 +57,7 @@ ) dbmanage = DbManage(dbconf=dbconf, root=kallithea.CONFIG['here'], tests=False, cli_args=cli_args) - dbmanage.create_tables(override=True) + dbmanage.create_tables() repo_root_path = dbmanage.prompt_repo_root_path(None) dbmanage.create_settings(repo_root_path) dbmanage.create_default_user() diff -r 7b0aafc6b7ca -r e1f233b069b0 kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py Mon Jun 15 17:27:19 2020 +0200 +++ b/kallithea/lib/db_manage.py Fri Jun 19 17:24:36 2020 +0200 @@ -72,7 +72,7 @@ init_model(engine) self.sa = Session() - def create_tables(self, override=False): + def create_tables(self): """ Create a auth database """ @@ -110,8 +110,7 @@ # known to work on SQLite - possibly not on other databases with strong referential integrity Base.metadata.drop_all() - checkfirst = not override - Base.metadata.create_all(checkfirst=checkfirst) + Base.metadata.create_all(checkfirst=False) # Create an Alembic configuration and generate the version table, # "stamping" it with the most recent Alembic migration revision, to diff -r 7b0aafc6b7ca -r e1f233b069b0 kallithea/tests/fixture.py --- a/kallithea/tests/fixture.py Mon Jun 15 17:27:19 2020 +0200 +++ b/kallithea/tests/fixture.py Fri Jun 19 17:24:36 2020 +0200 @@ -366,7 +366,7 @@ dbmanage = DbManage(dbconf=dbconf, root=config['here'], tests=True) - dbmanage.create_tables(override=True) + dbmanage.create_tables() # for tests dynamically set new root paths based on generated content dbmanage.create_settings(dbmanage.prompt_repo_root_path(repos_test_path)) dbmanage.create_default_user()