Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4a110b9
feat: create docker-compose file
jacob-a-brown Jul 14, 2025
17d4ced
feat: set up pre-commit hooks
jacob-a-brown Jul 14, 2025
44a3924
feat" add pre-commit to requirements files
jacob-a-brown Jul 14, 2025
11f4598
Fix pre-commit configureation file name
jacob-a-brown Jul 14, 2025
05210b9
feat: update README to include pre-commit info
jacob-a-brown Jul 14, 2025
b4331b4
Merge branch 'jir-mvp' into jab-poc
jacob-a-brown Jul 14, 2025
a796dfc
fix: refactor docker directory structure
jacob-a-brown Jul 14, 2025
2793ea6
feat: docker compose and Dockerfile updates
jacob-a-brown Jul 14, 2025
8cc19e9
fix: update Dockerfile and docker-compose.yml
jacob-a-brown Jul 15, 2025
039d157
fix: archive timescale db dockerfile
jacob-a-brown Jul 15, 2025
431d097
feat: create dockerignore
jacob-a-brown Jul 15, 2025
48057fd
feat: update dependencies
jacob-a-brown Jul 15, 2025
94d4fe3
feat: alembic init
jacob-a-brown Jul 15, 2025
e7c143c
use environment variables for migrations
jacob-a-brown Jul 15, 2025
daa7beb
fix: import libraries for all migration files
jacob-a-brown Jul 15, 2025
b0d40b9
set up docker
jacob-a-brown Jul 15, 2025
c014142
fix: use shell script to wait for db connection ready
jacob-a-brown Jul 15, 2025
27550ca
style: clarify echo statement
jacob-a-brown Jul 22, 2025
93d8bb4
feat: initial migration script
jacob-a-brown Jul 22, 2025
fb57626
fix: drop idx_location_point index if exists before migration
jacob-a-brown Jul 22, 2025
11d42cb
fix: make initial migration script compatible with PostGIS
jacob-a-brown Jul 22, 2025
3f07e52
fix: drop idx_location_point index if exists
jacob-a-brown Jul 22, 2025
bdac0f3
fix: avoid creating migration scripts in docker
jacob-a-brown Jul 22, 2025
42fcbda
Formatting changes
jacob-a-brown Jul 22, 2025
6dc7528
fix: make alembic migrations compatible with PostGIS and TIGER tables
jacob-a-brown Jul 22, 2025
458c110
fix: drop index if exists before creating it
jacob-a-brown Jul 22, 2025
f995af4
Merge branch 'jab-poc' of https://github.com/DataIntegrationGroup/NMS…
jacob-a-brown Jul 22, 2025
d6d622c
fix: keep sh script endings LF
jacob-a-brown Jul 22, 2025
a2ceeb0
fix: use .env POSTGRES_HOST for local env, db for docker
jacob-a-brown Jul 22, 2025
417290e
Formatting changes
jacob-a-brown Jul 22, 2025
ea9a19e
Merge branch 'pre-production' into jab-poc
jacob-a-brown Jul 22, 2025
3b4dcb5
feat: add pre-commit to pyproject
jacob-a-brown Jul 22, 2025
fa4205e
fix: update uv.lock
jacob-a-brown Jul 22, 2025
3367d54
fix: install dev dependencies with uv
jacob-a-brown Jul 22, 2025
4f43432
feat: update migration from pre-production changes
jacob-a-brown Jul 22, 2025
3355c2e
Merge branch 'jab-poc' of https://github.com/DataIntegrationGroup/NMS…
jacob-a-brown Jul 22, 2025
72144ea
feat: autoreload changes
jacob-a-brown Jul 22, 2025
fc231ee
Adds platform to docker-compose
chasetmartin Jul 22, 2025
720979e
fix: use latest version of postgis
jacob-a-brown Jul 22, 2025
a81f022
fix: load env vars for engine connect
jacob-a-brown Jul 22, 2025
9b78e5d
fix: set env vars in docker compose
jacob-a-brown Jul 22, 2025
f5461e9
fix: add alembic.ini to GitHub repo
jacob-a-brown Jul 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ migrate.sh


# deployment files
app.yaml
alembic.ini
app.yaml
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
args: [
'--count',
'--select=E9,F63,F7,F82,F401,F541,F631,F634,F701,F702',
'--show-source',
'--statistics'
]

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.10.0 # Use the latest stable version or pin to your preference
# hooks:
# - id: mypy
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ uv venv
source .venv/bin/activate
uv pip install -r requirements.txt

# Set up pre-commit hooks
pre-commit install

# Set up environment variables
cp .env.example .env
# Edit `.env` to configure database connection and app settings
Expand Down
141 changes: 141 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts.
# this is typically a path given in POSIX (e.g. forward slashes)
# format, relative to the token %(here)s which refers to the location of this
# ini file
script_location = %(here)s/alembic

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory. for multiple paths, the path separator
# is defined by "path_separator" below.
prepend_sys_path = .


# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =

# max length of characters to apply to the "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to <script_location>/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "path_separator"
# below.
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions

# path_separator; This indicates what character is used to split lists of file
# paths, including version_locations and prepend_sys_path within configparser
# files such as alembic.ini.
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
# to provide os-dependent path splitting.
#
# Note that in order to support legacy alembic.ini files, this default does NOT
# take place if path_separator is not present in alembic.ini. If this
# option is omitted entirely, fallback logic is as follows:
#
# 1. Parsing of the version_locations option falls back to using the legacy
# "version_path_separator" key, which if absent then falls back to the legacy
# behavior of splitting on spaces and/or commas.
# 2. Parsing of the prepend_sys_path option falls back to the legacy
# behavior of splitting on spaces, commas, or colons.
#
# Valid values for path_separator are:
#
# path_separator = :
# path_separator = ;
# path_separator = space
# path_separator = newline
#
# Use os.pathsep. Default configuration used for new projects.
path_separator = os

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

# database URL. This is consumed by the user-maintained env.py script only.
# other means of configuring database URLs may be customized within the env.py
# file.
sqlalchemy.url =


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = check --fix REVISION_SCRIPT_FILENAME

# Logging configuration. This is also consumed by the user-maintained
# env.py script only.
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARNING
handlers = console
qualname =

[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
2 changes: 1 addition & 1 deletion alembic/README
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pyproject configuration, based on the generic configuration.
Generic single-database configuration.
43 changes: 29 additions & 14 deletions alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from alembic import context
from dotenv import load_dotenv
from logging.config import fileConfig

from os import environ
from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -19,35 +20,46 @@
# from myapp import mymodel

# from db import Base # Import your Base from models/__init__.py
from db import *
from db import Base

# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata
model_tables = set(target_metadata.tables.keys())

# 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.

load_dotenv()

def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
# Fallback to environment variables for PostgreSQL connection
user = environ.get("POSTGRES_USER", None)
password = environ.get("POSTGRES_PASSWORD", None)
db = environ.get("POSTGRES_DB", None)
host = environ.get("POSTGRES_HOST", None)
port = environ.get("POSTGRES_PORT", None)
SQLALCHEMY_DATABASE_URL = f"postgresql+psycopg2://{user}:{password}@{host}:{port}/{db}"

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
config.set_main_option("sqlalchemy.url", SQLALCHEMY_DATABASE_URL)

Calls to context.execute() here emit the given string to the
script output.

"""
def include_object(object, name, type_, reflected, compare_to):
# only include tables in sql alchemy model, not auto-generated tables from PostGIS or TIGER
if type_ == "table":
return name in model_tables
return True


def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode."""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
include_object=include_object,
)

with context.begin_transaction():
Expand All @@ -68,8 +80,11 @@ def run_migrations_online() -> None:
)

with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)

context.configure(
connection=connection,
target_metadata=target_metadata,
include_object=include_object,
)
with context.begin_transaction():
context.run_migrations()

Expand Down
4 changes: 3 additions & 1 deletion alembic/script.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ Create Date: ${create_date}
from typing import Sequence, Union

from alembic import op
import geoalchemy2
import sqlalchemy as sa
import sqlalchemy_utils
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
down_revision: Union[str, Sequence[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)}

Expand Down
Loading
Loading