moonstream/moonstreamdb
Andrey 3bd8a68bd7 Add migration file. 2024-04-17 04:14:36 +03:00
..
alembic Add migration file. 2024-04-17 04:14:36 +03:00
configs Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
deploy Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
moonstreamdb Fix Networks mapping. 2024-04-17 03:33:44 +03:00
scripts Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
server Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
.dockerignore Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
.gitignore Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
.isort.cfg ZkSync Era testnet model 2023-07-12 11:23:00 +00:00
Dockerfile Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
README.md Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
alembic.sh Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
migrate.sh Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
mypy.ini Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
scm.nix Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
setup.py Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00
sync_conf.yml Updated moonstreamdb placement 2023-06-06 11:49:42 +00:00

README.md

moonstream db

Setting up moonstreamdb

Copy sample.env to a new file and set the environment variables to appropriate values. This new file should be sourced every time you want to access the database with the moonstreamdb application or any dependents.

To be able to run migrations, copy alembic.sample.ini to a separate file (e.g. ./secrets/alembic.dev.ini) and modify the sqlalchemy.url setting in the new file to point at your database.

Make sure your database is at the latest alembic migration:

alembic -c ./secrets/alembic.dev.ini upgrade head

Adding a new table to database

Add SQLAlchemy model in moonstreamdb/models.py

Import new model and add tablename to whitelist in alembic/env.py

Create a migration:

alembic -c <alembic config file> revision -m "<revision message>" --autogenerate

Always check the autogenerated file to make sure that it isn't performing any actions that you don't want it to. A good policy is to delete any operations that don't touch the tables that you created.

Then run the migration:

alembic -c <alembic config file> upgrade head