Metadata-Version: 2.1
Name: moonstreamdb
Version: 0.4.6
Summary: Moonstream database
Home-page: https://github.com/bugout-dev/moonstream
Author: Bugout.dev
Author-email: engineers@bugout.dev
License: Apache License 2.0
Platform: all
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: alembic
Requires-Dist: psycopg2-binary
Requires-Dist: sqlalchemy>=2.0.4
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Provides-Extra: distribute
Requires-Dist: build; extra == "distribute"
Requires-Dist: twine; extra == "distribute"

# 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`](./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:

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

### Adding a new table to database

Add SQLAlchemy model in [`moonstreamdb/models.py`](./moonstreamdb/models.py)

Import new model and add tablename to whitelist in [`alembic/env.py`](.alembic/env.py)

Create a migration:

```bash
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:

```bash
alembic -c <alembic config file> upgrade head
```
