mirror of
https://github.com/DarrylNixon/ghostforge
synced 2024-04-22 06:27:20 -07:00
Add initial alembic migration before turning in
This commit is contained in:
parent
425780f8a4
commit
ce30df0520
5 changed files with 51 additions and 18 deletions
|
@ -6,7 +6,6 @@ repos:
|
|||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: check-added-large-files
|
||||
exclude: 'ghostforge/static/js/es6/faker-8.0.2.mjs'
|
||||
- repo: https://github.com/asottile/reorder_python_imports
|
||||
rev: v3.9.0
|
||||
hooks:
|
||||
|
@ -27,3 +26,4 @@ repos:
|
|||
rev: 6.0.0
|
||||
hooks:
|
||||
- id: flake8
|
||||
exclude: ^migrations/versions/
|
||||
|
|
|
@ -58,7 +58,10 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
|
|||
# are written from script.py.mako
|
||||
# output_encoding = utf-8
|
||||
|
||||
sqlalchemy.url = postgresql+asyncpg://%(POSTGRES_USER)s:%(POSTGRES_PASSWORD)s@%(POSTGRES_CONTAINER)s:5432/%(POSTGRES_DB)s
|
||||
# This variable is replaced at runtime in env.py with environment variables
|
||||
# since they can't be nicely replaced/substituted within a configuration file
|
||||
sqlalchemy.url = placeholder
|
||||
|
||||
|
||||
[post_write_hooks]
|
||||
# post_write_hooks defines scripts or Python functions that are run
|
||||
|
|
|
@ -1,29 +1,17 @@
|
|||
import asyncio
|
||||
import os
|
||||
from logging.config import fileConfig
|
||||
from os import getenv as env
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import pool
|
||||
from sqlalchemy.engine import Connection
|
||||
from sqlalchemy.ext.asyncio import async_engine_from_config
|
||||
|
||||
from ghostforge.db import Base
|
||||
|
||||
# from ghostforge.models import User
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
section = config.config_ini_section
|
||||
|
||||
# this is ghostforge-specific, and loads the POSTGRES_*
|
||||
# environment variables from .env into the alembic context
|
||||
# for use in dynamically building the postgres URL string.
|
||||
for var in os.environ:
|
||||
if var.startswith("POSTGRES_"):
|
||||
config.set_section_option(section, var, os.environ.get(var))
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name is not None:
|
||||
|
@ -33,7 +21,7 @@ if config.config_file_name is not None:
|
|||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
target_metadata = Base.metadata
|
||||
target_metadata = SQLModel.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
|
@ -78,8 +66,20 @@ async def run_async_migrations() -> None:
|
|||
|
||||
"""
|
||||
|
||||
cfg = config.get_section(config.config_ini_section, {})
|
||||
cfg["sqlalchemy.url"] = (
|
||||
"postgresql+asyncpg://"
|
||||
+ env("POSTGRES_USER")
|
||||
+ ":"
|
||||
+ env("POSTGRES_PASSWORD")
|
||||
+ "@"
|
||||
+ env("POSTGRES_CONTAINER")
|
||||
+ ":5432/"
|
||||
+ env("POSTGRES_DB")
|
||||
)
|
||||
|
||||
connectable = async_engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
cfg,
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
|
|
@ -7,6 +7,7 @@ Create Date: ${create_date}
|
|||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
|
|
29
migrations/versions/e12aedb1fb49_init.py
Normal file
29
migrations/versions/e12aedb1fb49_init.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
"""init
|
||||
|
||||
Revision ID: e12aedb1fb49
|
||||
Revises:
|
||||
Create Date: 2023-06-02 19:37:26.134573
|
||||
|
||||
"""
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "e12aedb1fb49"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue