Archive

Archive for May, 2020

heroku – alembic

May 2, 2020 Leave a comment

Problem:
Alembic migrations are not run automatically on heroku. On first install of the application, attempting to run $heroku run alembic upgrade head --app application-name results in an error as it appears that tables are build from the models that were defined in the application.

$ heroku run alembic history --app application-name
$ heroku run alembic downgrade -1 --app application-name fails with

INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
ERROR [alembic.util.messaging] Relative revision -1 didn't produce 1 migrations
FAILED: Relative revision -1 didn't produce 1 migrations

$ heroku run alembic downgrade 017e517ce319 --app application-name fails with
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
ERROR [alembic.util.messaging] Destination 017e517ce319 is not a valid downgrade target from current head(s)
FAILED: Destination 017e517ce319 is not a valid downgrade target from current head(s)

On checking the alembic version in the database
$ heroku pg:psql DATABASE_URL --app application-name
application-name::DATABASE=>select * from alembic_version;
version_num
-------------
(0 rows)

application-name::DATABASE=> update alembic_version set version_num = '017e517ce319';
UPDATE 0
application-name::DATABASE=> select * from alembic_version;
version_num
-------------
(0 rows)

Solution:
To start using alembic I needed to drop all tables and run alembic. Doing a dump of the db, running alembic, then reading back the dump should also work.

1. Clear all data
$ heroku run pg:reset DATABASE_URL --app application-name
2. Run alembic
3. Moving forward, always manually run alembic. (You could add this to your deploy step as well, depends on your needs.)
4. alembic downgrade,upgrade should now work.

Categories: postgresql Tags: , , ,

https://use-the-index-luke.com/

May 1, 2020 Leave a comment

A site explaining SQL indexing to developers—no crap about administration.

SQL indexing is the most effective tuning method—yet it is often neglected during development. Use The Index, Luke explains SQL indexing from grounds up and doesn’t stop at ORM tools like Hibernate.

Use The Index, Luke is the free web-edition of SQL Performance Explained. If you like this site, consider getting the book. Also have a look at the shop for other cool stuff that supports this site.

https://use-the-index-luke.com/

Categories: Interesting