-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,143 additions
and
1,522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import asyncio | ||
from logging.config import fileConfig | ||
|
||
from alembic import context | ||
from sqlalchemy.engine import Connection | ||
from sqlalchemy.ext.asyncio import create_async_engine | ||
|
||
from config import POSTGRES_URL | ||
from models.db import * # noqa: F403 | ||
from models.db.base import Base | ||
|
||
# this is the Alembic Config object, which provides | ||
# access to the values within the .ini file in use. | ||
config = context.config | ||
|
||
# Interpret the config file for Python logging. | ||
# This line sets up loggers basically. | ||
if config.config_file_name is not None: | ||
fileConfig(config.config_file_name) | ||
|
||
# add your model's MetaData object here | ||
# for 'autogenerate' support | ||
target_metadata = Base.metadata | ||
|
||
# other values from the config, defined by the needs of env.py, | ||
# can be acquired: | ||
# my_important_option = config.get_main_option("my_important_option") | ||
# ... etc. | ||
|
||
|
||
def do_run_migrations(connection: Connection) -> None: | ||
context.configure( | ||
connection=connection, | ||
target_metadata=target_metadata, | ||
) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() | ||
|
||
|
||
async def run_async_migrations() -> None: | ||
"""In this scenario we need to create an Engine | ||
and associate a connection with the context. | ||
""" | ||
|
||
connectable = create_async_engine(POSTGRES_URL) | ||
|
||
async with connectable.connect() as connection: | ||
await connection.run_sync(do_run_migrations) | ||
|
||
await connectable.dispose() | ||
|
||
|
||
def run_migrations_online() -> None: | ||
"""Run migrations in 'online' mode.""" | ||
|
||
asyncio.run(run_async_migrations()) | ||
|
||
|
||
run_migrations_online() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy import Text | ||
${imports if imports else ""} | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = ${repr(up_revision)} | ||
down_revision: Union[str, None] = ${repr(down_revision)} | ||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} | ||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} | ||
|
||
|
||
def upgrade() -> None: | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade() -> None: | ||
${downgrades if downgrades else "pass"} |
89 changes: 89 additions & 0 deletions
89
alembic_/versions/2024_04_02_1819-9f60c90e8a21_initial_migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"""Initial migration | ||
Revision ID: 9f60c90e8a21 | ||
Revises: | ||
Create Date: 2024-04-02 18:19:53.332510+00:00 | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
import models.geometry | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '9f60c90e8a21' | ||
down_revision: str | None = None | ||
branch_labels: str | Sequence[str] | None = None | ||
depends_on: str | Sequence[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.execute('CREATE EXTENSION IF NOT EXISTS postgis;') | ||
|
||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
'aed', | ||
sa.Column('id', sa.BigInteger(), nullable=False), | ||
sa.Column('version', sa.BigInteger(), nullable=False), | ||
sa.Column('tags', postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.Column('position', models.geometry.PointType(), nullable=False), | ||
sa.Column('country_codes', sa.ARRAY(sa.Unicode(length=8), dimensions=1), nullable=True), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
op.create_index('aed_country_codes_idx', 'aed', ['country_codes'], unique=False, postgresql_using='gin') | ||
op.create_index('aed_position_idx', 'aed', ['position'], unique=False, postgresql_using='gist') | ||
op.create_table( | ||
'country', | ||
sa.Column('code', sa.Unicode(length=8), nullable=False), | ||
sa.Column('names', postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.Column('geometry', models.geometry.PolygonType(), nullable=False), | ||
sa.Column('label_position', models.geometry.PointType(), nullable=False), | ||
sa.PrimaryKeyConstraint('code'), | ||
) | ||
op.create_index('country_geometry_idx', 'country', ['geometry'], unique=False, postgresql_using='gist') | ||
op.create_table( | ||
'photo', | ||
sa.Column('id', sa.Unicode(length=32), nullable=False), | ||
sa.Column('node_id', sa.BigInteger(), nullable=False), | ||
sa.Column('user_id', sa.BigInteger(), nullable=False), | ||
sa.Column( | ||
'created_at', | ||
postgresql.TIMESTAMP(timezone=True), | ||
server_default=sa.text('statement_timestamp()'), | ||
nullable=False, | ||
), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
op.create_table( | ||
'state', | ||
sa.Column('key', sa.Unicode(), nullable=False), | ||
sa.Column('data', postgresql.JSONB(astext_type=sa.Text()), nullable=False), | ||
sa.PrimaryKeyConstraint('key'), | ||
) | ||
op.create_table( | ||
'photo_report', | ||
sa.Column('id', sa.Unicode(length=32), nullable=False), | ||
sa.Column('photo_id', sa.Unicode(length=32), nullable=False), | ||
sa.Column( | ||
'created_at', | ||
postgresql.TIMESTAMP(timezone=True), | ||
server_default=sa.text('statement_timestamp()'), | ||
nullable=False, | ||
), | ||
sa.ForeignKeyConstraint( | ||
['photo_id'], | ||
['photo.id'], | ||
), | ||
sa.PrimaryKeyConstraint('id'), | ||
) | ||
op.create_index('photo_report_created_at_idx', 'photo_report', ['created_at'], unique=False) | ||
op.create_index('photo_report_photo_id_idx', 'photo_report', ['photo_id'], unique=True) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.