Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear postgresql and alembic and start over from scratch

Everything I found about this via searching was either wrong or incomplete in some way. So, how do I:

  • delete everything in my postgresql database
  • delete all my alembic revisions
  • make it so that my database is 100% like new
like image 906
lynn Avatar asked Jul 13 '15 19:07

lynn


3 Answers

This works for me:

1) Access your session, in the same way you did session.create_all, do session.drop_all.

2) Delete the migration files generated by alembic.

3) Run session.create_all and initial migration generation again.

like image 81
brandonjschwartz Avatar answered Oct 11 '22 15:10

brandonjschwartz


No idea how to mess with alembic, but for the database, you can just log into the SQL console and use DROP DATABASE foo.

Or were you wanting to clear out all the data, but leave the tables there? If so, Truncating all tables in a postgres database has some good answers.

like image 24
Xanthir Avatar answered Oct 11 '22 13:10

Xanthir


If you want to do this without dropping your migration files the steps are:

  1. Drop all the tables in the db that are to be recreated.
  2. Truncate the alembic_version table (so it will start from the beginning) - this is where the most recent version is kept.

The you can run:

alembic upgrade head

and everything will be recreated. I ran into this problem when my migrations got in a weird state during development and I wanted to reset alembic. This worked.

like image 23
C.J. Windisch Avatar answered Oct 11 '22 15:10

C.J. Windisch