oasis-art-project / oasis-server

Platform for the local arts
Other
2 stars 0 forks source link

SQLAlchemy 1.4.x breaks database migration in Heroku #97

Open codeanticode opened 3 years ago

codeanticode commented 3 years ago

Discussed here: https://github.com/sqlalchemy/sqlalchemy/issues/6083

Also: https://help.heroku.com/ZKNTJQSK/why-is-sqlalchemy-1-4-x-not-connecting-to-heroku-postgres

codeanticode commented 3 years ago

The problem is that Heroku still uses postgres:// for the url of PostgresSQL DBs, which has been deprecated in SQLAlchemy 1.4.x. The OASIS server does not use the deprecated url, but during migration, the SQLALCHEMY_DATABASE_URI is generated automatically by Heroku with the deprecated URL. In migration/env.py one would need to change:

from flask import current_app

db_uri = current_app.config.get(
        'SQLALCHEMY_DATABASE_URI').replace('%', '%%')
config.set_main_option('sqlalchemy.url', db_uri)

with

from flask import current_app

db_uri = current_app.config.get('SQLALCHEMY_DATABASE_URI').replace('%', '%%')
if db_uri.startswith("postgres://"):
    db_uri = db_uri.replace("postgres://", "postgresql://", 1)
config.set_main_option('sqlalchemy.url', db_uri)
target_metadata = current_app.extensions['migrate'].db.metadata 

but env.py is autogenerated… so not sure how to fix.

For the time being, setting the SQLAlchemy version in the requirements to 1.3.24 seems enough: https://github.com/codeanticode/oasis-server/commit/bb24af1e47db21643f29eb48b93ede62a0d40d49