25 Commits

Author SHA1 Message Date
Ben Sturmfels
dec47c7102 Apply pyupgrade --py3-plus to remove Python 2 compatibility code. 2021-03-05 23:12:19 +11:00
Boris Bobrov
b3429ec69c move alembic.ini to python app dir 2017-11-14 22:01:19 +03:00
Christopher Allan Webber
f25b476202 Only run sqlalchemy-migrate migrations if we have to; separate foundations
The goal is to get things to the point where Alembic can run on its own
for new databases and initialize the whole database on its own.  There
are risks to not doing so, see #5413 for details.

There's a lot more here that could removed or cleaned up once
sqlalchemy-migrate is *completely* removed in the future.

* mediagoblin/db/migration_tools.py (MigrationManager.foundations):
  Removed attribute.
  (MigrationManager.populate_table_foundations): Removed method.
  (MigrationManager.init_or_migrate): Removed call to deprecated method.
  (populate_table_foundations): New function, refactored from former
  MigrationManager method of same name.

* mediagoblin/gmg_commands/dbupdate.py: Import populate_table_foundations.
  (DatabaseData.foundations): Remove attribute.
  (DatabaseData.make_migration_manager): Adjust instantiation of
  MigrationManager.
  (gather_database_data): Move out the work of building up foundations data.
  (run_foundations): New method, incorporating logic for gathering and
  running foundations which was previously spread across other
  functions and methods.
  (run_alembic_migrations): Remove deprecated comment.
  (run_dbupdate): Only run sqlalchemy migrations if we have to.
  Also run run_foundations if we are setting up this database for the
  first time.
  (sqam_migrations_to_run): New method.
2016-03-26 11:39:07 -07:00
Christopher Allan Webber
05879c1c76 dbupdate updates to use plugin migrations if available
This makes use of the recently added "build_alembic_config" tool and
removes AlembicMigrationManager.

* mediagoblin/db/migration_tools.py (AlembicMigrationManager): Removed.
* mediagoblin/gmg_commands/dbupdate.py (run_alembic_migrations):
  Adjusted to use recently added build_alembic_config tool.
2016-03-26 11:39:07 -07:00
Christopher Allan Webber
6e9041aa4b Add build_alembic_config, use it to add plugin migrations to alembic config 2016-03-26 11:39:07 -07:00
Christopher Allan Webber
a48736fc09 typo fix: Set sqlalchemy.url, not qlalchemy.url 2016-03-02 16:08:12 -08:00
Christopher Allan Webber
af6b89eafe Remove old hack to support pre-0.7.5 Alembic versions
Thanks to Jessica Tallon for pointing out this TODO and its associated
hack could be removed.
2016-03-02 11:20:47 -08:00
Jessica Tallon
4c77f3d563 Fix #5398 and #5395 - Fix tests failing due to problem creating connection for alembic
For some reason the alembic connection wasn't seeing any tables that existed
however the existing connection works well and we shouldn't be creating a brand
new one when we have one ready to use. I've used a little bit of a hack due to our
old version of alembic.

After 0.7.5 of alembic it offers a `Config.attributes` dictionary which is designed to
allow you to pass your connection/engine/whatever to the env.py config script so you're
not required to create new ones. As we're on an older version I just create a dictionary
with the same name and use it as otherwise documented. It seems this is the suggested
fix for #5395 and it fixes #5398 too.
2016-01-20 09:09:42 +00:00
Jessica Tallon
2ddebb97bf Fix #5391 - Alembic migrations would only work for SQLite
The database connection was being set in a alembic.ini config file, if the user
had specified postgres the "sqlite" connection URL in alembic.ini would override
that. We probably should look into this more so i've opened #5395.
2016-01-18 09:39:34 +00:00
Boris Bobrov
2b68834c44 Enable alembic as the main tool for migrations
Enable alembic for all migrations and limit the max number of
sqlalchemy-migration migration. All new migrations must now be in
Alembic!
2016-01-11 07:14:33 -08:00
Jessica Tallon
0ae15357eb Fix a exception db closed exception in migrations
Some sqlite migrations were failing due to some problems with sqlite. A
work around has been created for these however it does involve loading lots
of data into memory. If you have a large database you should consider trying
to move to postgres.
2015-12-29 16:42:37 +00:00
Berker Peksag
2ace351bed Do not call AlembicMigrationManager.init_tables() for now.
sqlalchemy-migrate will do this for us.
2014-10-02 20:18:29 +03:00
Berker Peksag
de51eca53f Provide a better manager API for Alembic. 2014-08-15 15:39:45 +03:00
Berker Peksag
65f20ca435 Add initial Alembic migrations. 2014-08-13 19:30:23 +03:00
Berker Peksag
98d8b365af func_name removed in Python 3. 2014-07-28 10:35:14 +03:00
Berker Peksag
7f342c72f6 Continue to port GMG codebase. 2014-05-08 20:33:14 +03:00
Christopher Allan Webber
0c875e1e96 Renaming replace_table to replace_table_hack and documenting why it's a hack
We'd still prefer people use other solutions when possible!

This commit sponsored by Michał Masłowski.  Thank you!
2013-10-10 14:22:38 -05:00
Christopher Allan Webber
454a2c16bd Actually rename the table back, or else we just lose the old table! ;) 2013-10-10 14:14:32 -05:00
tilly-Q
e5196ff000 I made some changes in this commit to help out with other people trying to work
around the SQLite problems with Alter table. I added a new function to
migration_tools (replace_table) which does all the work I did in my migration of
core__users, but is now usable for other migrations.
2013-10-09 17:11:41 -04:00
tilly-Q
63c3ca28ab Starting to write unit tests... 2013-07-30 19:06:26 -04:00
tilly-Q
08cd10d84f I actually had to do a bit more work than I thought, because I needed to account
for plugins. In this commit I changed the MigrationManager and DatabaseData ob-
jects to account for FOUNDATIONS in any plugin's (or main program's) models.py
file.
2013-07-29 17:15:29 -04:00
tilly-Q
f2b2008da5 This was a very simple ticket actually. I created a list called FOUNDATIONS in
mediagoblin/db/models.py. This list holds all of the information about rows that
should be created at database initialization. Read the documentation near the
FOUNDATIONS list to understand the proper format for this list.

All of the work is done through a new method on MigrationManager in
mediagoblin/db/migrations_tools.py. This method, `populate_table_foundations`
parses the FOUNDATIONS list and creates the foundations based on the data incl-
uded. This only ever happens when the database is initialized. Migrations to
releases with new Foundations should be very easy just using the basic
database functionality.
2013-07-29 16:36:06 -04:00
Christopher Allan Webber
003ea47499 Changing the information spat out while printing from media types->plugins
Previously it called even plugins media types.  Ha!

This commit sponsored by Jon Merkley.  Thank you!
2013-07-12 14:16:47 -05:00
Christopher Allan Webber
7e4a87dca5 Give a more useful error if a table already exists and so we can't create it during migrations
This commit sponsored by Andrzej Prochyra.  Thanks!
2013-03-04 10:57:21 -06:00
Elrond
c130e3ee79 Move db.sql.migration_tools to db.migration_tools.
Follow the new trend.
2013-01-08 22:50:01 +01:00