From c31856a91fc05f318e3d517e6d9c47da1c299f5e Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 15:34:17 -0400 Subject: [PATCH 01/48] init --- .github/workflows/db-changes-var1.yaml | 146 +++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 .github/workflows/db-changes-var1.yaml diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml new file mode 100644 index 0000000..eb6549c --- /dev/null +++ b/.github/workflows/db-changes-var1.yaml @@ -0,0 +1,146 @@ +name: DB Change Check var1 + +on: + pull_request: + branches: + - main + +jobs: + check-sql-schema-changes: + runs-on: ubuntu-latest + steps: + - name: Checkout Branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check For Changes + id: changed-db-files + uses: tj-actions/changed-files@v44 + with: + files: "app/**" + + - name: Check Conditions + id: check-conditions + run: | + echo "DB_CHANGE=${{ steps.changed-db-files.outputs.any_changed }}" >> $GITHUB_ENV + + run-alembic: + needs: check-sql-schema-changes + # if: ${{ needs.check-sql-schema-changes.DB_CHANGE == 'true' }} + runs-on: ubuntu-latest + + services: + postgres: + image: postgis/postgis:14-3.4 + env: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + POSTGRES_HOST: localhost + POSTGRES_DRIVERNAME: postgresql + options: >- + --health-cmd pg_isready + --health-interval 5s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - name: Drop unwanted PostGIS extensions + run: | + psql -h localhost -U postgres -d postgres -c "DROP EXTENSION IF EXISTS postgis_tiger_geocoder CASCADE;" + psql -h localhost -U postgres -d postgres -c "DROP EXTENSION IF EXISTS postgis_topology CASCADE;" + psql -h localhost -U postgres -d postgres -c "DROP EXTENSION IF EXISTS fuzzystrmatch CASCADE;" + + env: + PGPASSWORD: postgres + + - name: Checkout Main Branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + # ref: 'main' + + - name: Set up Python + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Generate envs & set path + id: generate-envs + run: | + DATABASE_URL="postgresql://postgres:postgres@localhost:5432" + echo "DATABASE_URL=$DATABASE_URL" >> $GITHUB_ENV + echo "PYTHONPATH=$PYTHONPATH:$(pwd)" >> $GITHUB_ENV + + - name: Install dependencies + id: install-dependencies + run: | + python -m pip install --upgrade pip + pip install -r app/requirements.txt + + - name: Run alembic script autogeneration for Initial DB Setup + id: run-alembic-script-autogen + env: + DATABASE_URL: ${{ env.DATABASE_URL }} + run: | + alembic -c alembic.ini revision --autogenerate -m "test_temp_db_001" + + - name: Alembic Upgrade Head + id: run-alembic-upgrade-initial + env: + DATABASE_URL: ${{ env.DATABASE_URL }} + run: | + alembic -c alembic.ini upgrade head + + - name: Checkout New Branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run alembic script autogeneration + id: run-alembic-script-autogen-round-2 + env: + DATABASE_URL: ${{ env.DATABASE_URL }} + run: | + alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" + + - name: Upgrade alembic head with new revision + id: run-alembic-upgrade-new + env: + DATABASE_URL: ${{ env.DATABASE_URL }} + run: | + alembic -c alembic.ini upgrade head + + - name: Test DB is set up correctly + id: test-db-set-up + run: | + set -e # catch errors + python migrations/test_migration.py + + # - name: Checkout new branch + # id: checkout-new-branch + # run: | + # git config --global user.email "github-actions[bot]@users.noreply.github.com" + # git config --global user.name "github-actions[bot]" + # git checkout -b ${{ env.BRANCH_NAME }} + # git push origin ${{ env.BRANCH_NAME }} + + # - name: Add alembic script to new branch + # id: add-alembic-script-to-new-branch + # run: | + # git add . + # git commit -m "Add new Alembic migration" + # git push origin HEAD:${{ github.ref }} + + # - name: Create PR + # id: create-pull-request + # uses: peter-evans/create-pull-request@v5 + # with: + # branch: ${{ env.BRANCH_NAME }} + # base: main + # title: "BotPR: {{ env.BRANCH_NAME }}" + # author: "github-actions[bot] " + From 99d03ed7c4c90a14d3cb5989697f6b2495f76e9e Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 15:37:17 -0400 Subject: [PATCH 02/48] add init to versions --- .github/workflows/db-changes-var1.yaml | 2 +- migrations/versions/__init__.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 migrations/versions/__init__.py diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index eb6549c..8a684c0 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -81,7 +81,7 @@ jobs: python -m pip install --upgrade pip pip install -r app/requirements.txt - - name: Run alembic script autogeneration for Initial DB Setup + - name: Run alembic script autogen for Initial DB Setup id: run-alembic-script-autogen env: DATABASE_URL: ${{ env.DATABASE_URL }} diff --git a/migrations/versions/__init__.py b/migrations/versions/__init__.py new file mode 100644 index 0000000..e69de29 From 0e111fd48a1595bc08ebbd05d30c74db1f5e861b Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 15:42:55 -0400 Subject: [PATCH 03/48] make sure revision script is in the new branch too --- .github/workflows/db-changes-var1.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 8a684c0..1bf359a 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -100,6 +100,11 @@ jobs: with: fetch-depth: 0 + - name: Merge with Main + description: Make sure new migration file that was generated in main exists in new branch + run: | + git merge main + - name: Run alembic script autogeneration id: run-alembic-script-autogen-round-2 env: From b3c2f43ea1ebfc82ddea9277e4cc52f20c5e56b4 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 15:44:00 -0400 Subject: [PATCH 04/48] oops no description --- .github/workflows/db-changes-var1.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 1bf359a..48c8510 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -101,9 +101,9 @@ jobs: fetch-depth: 0 - name: Merge with Main - description: Make sure new migration file that was generated in main exists in new branch run: | git merge main + # Make sure new migration file that was generated in main exists in new branch - name: Run alembic script autogeneration id: run-alembic-script-autogen-round-2 From aeb9e710d8a9d3ca7667f0d8eb7e97435921f78d Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 17:01:31 -0400 Subject: [PATCH 05/48] lemme see that git status --- .github/workflows/db-changes-var1.yaml | 52 +++++++++++++------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 48c8510..ab1b806 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -1,4 +1,4 @@ -name: DB Change Check var1 +name: DB Change Check var1 - K on: pull_request: @@ -56,7 +56,7 @@ jobs: env: PGPASSWORD: postgres - - name: Checkout Main Branch + - name: Checkout Branch uses: actions/checkout@v4 with: fetch-depth: 0 @@ -94,36 +94,34 @@ jobs: DATABASE_URL: ${{ env.DATABASE_URL }} run: | alembic -c alembic.ini upgrade head + git status - - name: Checkout New Branch - uses: actions/checkout@v4 - with: - fetch-depth: 0 + # - name: Checkout New Branch + # uses: actions/checkout@v4 + # with: + # fetch-depth: 0 - - name: Merge with Main - run: | - git merge main - # Make sure new migration file that was generated in main exists in new branch - - name: Run alembic script autogeneration - id: run-alembic-script-autogen-round-2 - env: - DATABASE_URL: ${{ env.DATABASE_URL }} - run: | - alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" - - name: Upgrade alembic head with new revision - id: run-alembic-upgrade-new - env: - DATABASE_URL: ${{ env.DATABASE_URL }} - run: | - alembic -c alembic.ini upgrade head + # - name: Run alembic script autogeneration + # id: run-alembic-script-autogen-round-2 + # env: + # DATABASE_URL: ${{ env.DATABASE_URL }} + # run: | + # alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" - - name: Test DB is set up correctly - id: test-db-set-up - run: | - set -e # catch errors - python migrations/test_migration.py + # - name: Upgrade alembic head with new revision + # id: run-alembic-upgrade-new + # env: + # DATABASE_URL: ${{ env.DATABASE_URL }} + # run: | + # alembic -c alembic.ini upgrade head + + # - name: Test DB is set up correctly + # id: test-db-set-up + # run: | + # set -e # catch errors + # python migrations/test_migration.py # - name: Checkout new branch # id: checkout-new-branch From ca9d4a7905a627e46c3e079af8c81a67b3b9624e Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 17:04:40 -0400 Subject: [PATCH 06/48] will you be my mom --- .github/workflows/db-changes-var1.yaml | 52 +++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index ab1b806..a7be480 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -56,11 +56,11 @@ jobs: env: PGPASSWORD: postgres - - name: Checkout Branch + - name: Checkout Main Branch uses: actions/checkout@v4 with: fetch-depth: 0 - # ref: 'main' + ref: 'main' - name: Set up Python id: setup-python @@ -94,34 +94,34 @@ jobs: DATABASE_URL: ${{ env.DATABASE_URL }} run: | alembic -c alembic.ini upgrade head - git status - - # - name: Checkout New Branch - # uses: actions/checkout@v4 - # with: - # fetch-depth: 0 - + git add . + git stash + - name: Checkout New Branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 - # - name: Run alembic script autogeneration - # id: run-alembic-script-autogen-round-2 - # env: - # DATABASE_URL: ${{ env.DATABASE_URL }} - # run: | - # alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" + - name: Run alembic script autogeneration + id: run-alembic-script-autogen-round-2 + env: + DATABASE_URL: ${{ env.DATABASE_URL }} + run: | + git stash pop + alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" - # - name: Upgrade alembic head with new revision - # id: run-alembic-upgrade-new - # env: - # DATABASE_URL: ${{ env.DATABASE_URL }} - # run: | - # alembic -c alembic.ini upgrade head + - name: Upgrade alembic head with new revision + id: run-alembic-upgrade-new + env: + DATABASE_URL: ${{ env.DATABASE_URL }} + run: | + alembic -c alembic.ini upgrade head - # - name: Test DB is set up correctly - # id: test-db-set-up - # run: | - # set -e # catch errors - # python migrations/test_migration.py + - name: Test DB is set up correctly + id: test-db-set-up + run: | + set -e # catch errors + python migrations/test_migration.py # - name: Checkout new branch # id: checkout-new-branch From 39e5aa69389f2902aec675dfe5646f0a464a1296 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 17:08:25 -0400 Subject: [PATCH 07/48] okkkk --- .github/workflows/db-changes-var1.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index a7be480..1be7b16 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -94,7 +94,7 @@ jobs: DATABASE_URL: ${{ env.DATABASE_URL }} run: | alembic -c alembic.ini upgrade head - git add . + git branch git stash - name: Checkout New Branch @@ -107,6 +107,7 @@ jobs: env: DATABASE_URL: ${{ env.DATABASE_URL }} run: | + git branch git stash pop alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" From a8fe8fa5f269f829146991ab112cfb44b93fe2e0 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 17:18:05 -0400 Subject: [PATCH 08/48] why are you like this --- .github/workflows/db-changes-var1.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 1be7b16..86cf759 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -95,6 +95,7 @@ jobs: run: | alembic -c alembic.ini upgrade head git branch + git status git stash - name: Checkout New Branch From 76756f5d0449f1ec802818e8e07f5c97602dfb72 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 17:22:33 -0400 Subject: [PATCH 09/48] will you be --- .github/workflows/db-changes-var1.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 86cf759..294746c 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -96,6 +96,7 @@ jobs: alembic -c alembic.ini upgrade head git branch git status + git add . git stash - name: Checkout New Branch From 881c03e99fc5d6ca766e445c85c83b5c699b3870 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 18:15:37 -0400 Subject: [PATCH 10/48] cat! --- .github/workflows/db-changes-var1.yaml | 1 + alembic.ini | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 294746c..0ad48d2 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -112,6 +112,7 @@ jobs: git branch git stash pop alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" + cat migrations/versions/test_new_changes_002.py - name: Upgrade alembic head with new revision id: run-alembic-upgrade-new diff --git a/alembic.ini b/alembic.ini index 58f98ec..d8a0020 100644 --- a/alembic.ini +++ b/alembic.ini @@ -8,7 +8,7 @@ script_location = ./migrations # 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-%%(rev)s +file_template = %%(slug)s # sys.path path, will be prepended to sys.path if present. # defaults to the current working directory. From 2bc3273eab6ff1858ee79fe3d0cd4c545224ce50 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 18:18:59 -0400 Subject: [PATCH 11/48] will this work? --- .github/workflows/db-changes-var1.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 0ad48d2..7b53157 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -103,8 +103,9 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + ref: 'add-gha-auto-db-migration' - - name: Run alembic script autogeneration + - name: Generate alembic script for new branch id: run-alembic-script-autogen-round-2 env: DATABASE_URL: ${{ env.DATABASE_URL }} From 9acb210c1bbc4b4df114efae315a6a52b72ff5eb Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 18:24:28 -0400 Subject: [PATCH 12/48] y u no work --- alembic.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic.ini b/alembic.ini index d8a0020..3612aa8 100644 --- a/alembic.ini +++ b/alembic.ini @@ -101,7 +101,7 @@ handlers = qualname = sqlalchemy.engine [logger_alembic] -level = INFO +level = DEBUG handlers = qualname = alembic From e7b4e61870c39db14350f6f7c9b56248fa34db4d Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Thu, 5 Sep 2024 18:26:49 -0400 Subject: [PATCH 13/48] all debug --- .github/workflows/db-changes-var1.yaml | 7 ++----- alembic.ini | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 7b53157..952e551 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -94,10 +94,8 @@ jobs: DATABASE_URL: ${{ env.DATABASE_URL }} run: | alembic -c alembic.ini upgrade head - git branch - git status git add . - git stash + git stash # add and stash the last revision script before switching branches - name: Checkout New Branch uses: actions/checkout@v4 @@ -110,8 +108,7 @@ jobs: env: DATABASE_URL: ${{ env.DATABASE_URL }} run: | - git branch - git stash pop + git stash pop # get the last revision script alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" cat migrations/versions/test_new_changes_002.py diff --git a/alembic.ini b/alembic.ini index 3612aa8..ca596ca 100644 --- a/alembic.ini +++ b/alembic.ini @@ -91,12 +91,12 @@ keys = console keys = generic [logger_root] -level = WARN +level = DEBUG handlers = console qualname = [logger_sqlalchemy] -level = WARN +level = DEBUG handlers = qualname = sqlalchemy.engine From 8ababfeef705c747b7cada45a9f2bbebda31b76f Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 11:01:06 -0400 Subject: [PATCH 14/48] don't assume transactional ddl --- migrations/env.py | 1 + 1 file changed, 1 insertion(+) diff --git a/migrations/env.py b/migrations/env.py index 30834d5..435bc98 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -98,6 +98,7 @@ def run_migrations_online() -> None: target_metadata=target_metadata, process_revision_directives=process_revision_directives, # Make sure geoalchemy import included with any autogen script include_object=include_object, + transactional_ddl=False, ) for schema in SCHEMATA: From 09e90d435ed22ed3cbbbab7c644458e08244e10e Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 11:12:42 -0400 Subject: [PATCH 15/48] UHHH --- migrations/env.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migrations/env.py b/migrations/env.py index 435bc98..c90b691 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -113,5 +113,7 @@ def run_migrations_online() -> None: if context.is_offline_mode(): run_migrations_offline() + print("RAN MIGRATION OFFLINE") else: run_migrations_online() + print("RAN MIGRATION ONLINE") From 6ea89666de1631bd009eda7a298fe24a1d05a67c Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 11:17:15 -0400 Subject: [PATCH 16/48] truly wild --- .github/workflows/db-changes-var1.yaml | 3 +++ migrations/env.py | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 952e551..5f8ed07 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -94,6 +94,9 @@ jobs: DATABASE_URL: ${{ env.DATABASE_URL }} run: | alembic -c alembic.ini upgrade head + + - name: Preserve migration script for new branch checkout + id: git-stash-migration-script git add . git stash # add and stash the last revision script before switching branches diff --git a/migrations/env.py b/migrations/env.py index c90b691..6f51d64 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -98,7 +98,8 @@ def run_migrations_online() -> None: target_metadata=target_metadata, process_revision_directives=process_revision_directives, # Make sure geoalchemy import included with any autogen script include_object=include_object, - transactional_ddl=False, + # transactional_ddl=False, + transaction_per_migration=True, ) for schema in SCHEMATA: @@ -113,7 +114,5 @@ def run_migrations_online() -> None: if context.is_offline_mode(): run_migrations_offline() - print("RAN MIGRATION OFFLINE") else: run_migrations_online() - print("RAN MIGRATION ONLINE") From 92b10058bee117074fde59afc89948cf46d38b0b Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 11:17:53 -0400 Subject: [PATCH 17/48] oops --- .github/workflows/db-changes-var1.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 5f8ed07..3399354 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -95,10 +95,11 @@ jobs: run: | alembic -c alembic.ini upgrade head - - name: Preserve migration script for new branch checkout + - name: Git stash migration script for new branch checkout id: git-stash-migration-script + run: | git add . - git stash # add and stash the last revision script before switching branches + git stash - name: Checkout New Branch uses: actions/checkout@v4 From aa6d9339033918158fd8ff0ab2208cf336e5f171 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 11:23:55 -0400 Subject: [PATCH 18/48] some new column --- app/tables.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/tables.py b/app/tables.py index 7a9b31e..3b9b680 100644 --- a/app/tables.py +++ b/app/tables.py @@ -68,3 +68,4 @@ class Trajectory(GISBase): __table_args__ = {"schema": "gps"} geom = mapped_column(Geometry("GEOMETRYZM", spatial_index=False)) feed_item_id = mapped_column(ForeignKey(FeedItem.id)) + some_new_field = mapped_column(String) From 0fffd1c65e1a4fce359daf2b7b3339823c9f59ee Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:09:04 -0400 Subject: [PATCH 19/48] yay --- migrations/env.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/migrations/env.py b/migrations/env.py index 6f51d64..498cd9d 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -98,8 +98,9 @@ def run_migrations_online() -> None: target_metadata=target_metadata, process_revision_directives=process_revision_directives, # Make sure geoalchemy import included with any autogen script include_object=include_object, - # transactional_ddl=False, - transaction_per_migration=True, + dialect_opts={"paramstyle": "named"}, + include_schemas=True, + include_name=include_name, ) for schema in SCHEMATA: @@ -112,6 +113,13 @@ def run_migrations_online() -> None: context.run_migrations() +def include_name(name, type_, parent_names): + if type_ == "schema": + return name in SCHEMATA + else: + return True + + if context.is_offline_mode(): run_migrations_offline() else: From 6f0552748fa7862026aa2dc656369ec2bccdbd64 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:11:25 -0400 Subject: [PATCH 20/48] test --- .github/workflows/db-changes-var1.yaml | 22 +++++------ migrations/versions/test_001.py | 53 ++++++++++++++++++++++++++ migrations/versions/test_02.py | 35 +++++++++++++++++ 3 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 migrations/versions/test_001.py create mode 100644 migrations/versions/test_02.py diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 3399354..2976268 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -81,12 +81,12 @@ jobs: python -m pip install --upgrade pip pip install -r app/requirements.txt - - name: Run alembic script autogen for Initial DB Setup - id: run-alembic-script-autogen - env: - DATABASE_URL: ${{ env.DATABASE_URL }} - run: | - alembic -c alembic.ini revision --autogenerate -m "test_temp_db_001" + # - name: Run alembic script autogen for Initial DB Setup + # id: run-alembic-script-autogen + # env: + # DATABASE_URL: ${{ env.DATABASE_URL }} + # run: | + # alembic -c alembic.ini revision --autogenerate -m "test_temp_db_001" - name: Alembic Upgrade Head id: run-alembic-upgrade-initial @@ -95,11 +95,11 @@ jobs: run: | alembic -c alembic.ini upgrade head - - name: Git stash migration script for new branch checkout - id: git-stash-migration-script - run: | - git add . - git stash + # - name: Git stash migration script for new branch checkout + # id: git-stash-migration-script + # run: | + # git add . + # git stash - name: Checkout New Branch uses: actions/checkout@v4 diff --git a/migrations/versions/test_001.py b/migrations/versions/test_001.py new file mode 100644 index 0000000..8f73112 --- /dev/null +++ b/migrations/versions/test_001.py @@ -0,0 +1,53 @@ +"""test_001 + +Revision ID: fbf2dd38133d +Revises: +Create Date: 2024-09-06 12:10:24.549138 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import geoalchemy2 + +# revision identifiers, used by Alembic. +revision: str = 'fbf2dd38133d' +down_revision: Union[str, None] = None +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('feed_item', + sa.Column('name', sa.String(), nullable=True), + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('create_time', sa.TIMESTAMP(), nullable=True), + sa.Column('updated_time', sa.TIMESTAMP(), nullable=True), + sa.PrimaryKeyConstraint('id'), + schema='gps' + ) + op.create_index(op.f('ix_gps_feed_item_id'), 'feed_item', ['id'], unique=False, schema='gps') + op.create_table('trajectory', + sa.Column('geom', geoalchemy2.types.Geometry(geometry_type='GEOMETRYZM', spatial_index=False, from_text='ST_GeomFromEWKT', name='geometry'), nullable=True), + sa.Column('feed_item_id', sa.UUID(), nullable=True), + sa.Column('some_new_field', sa.String(), nullable=True), + sa.Column('id', sa.UUID(), nullable=False), + sa.Column('create_time', sa.TIMESTAMP(), nullable=True), + sa.Column('updated_time', sa.TIMESTAMP(), nullable=True), + sa.ForeignKeyConstraint(['feed_item_id'], ['gps.feed_item.id'], ), + sa.PrimaryKeyConstraint('id'), + schema='gps' + ) + op.create_index(op.f('ix_gps_trajectory_id'), 'trajectory', ['id'], unique=False, schema='gps') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_gps_trajectory_id'), table_name='trajectory', schema='gps') + op.drop_table('trajectory', schema='gps') + op.drop_index(op.f('ix_gps_feed_item_id'), table_name='feed_item', schema='gps') + op.drop_table('feed_item', schema='gps') + # ### end Alembic commands ### diff --git a/migrations/versions/test_02.py b/migrations/versions/test_02.py new file mode 100644 index 0000000..9309894 --- /dev/null +++ b/migrations/versions/test_02.py @@ -0,0 +1,35 @@ +"""test_02 + +Revision ID: b011fca27a94 +Revises: fbf2dd38133d +Create Date: 2024-09-06 12:10:34.691538 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import geoalchemy2 + +# revision identifiers, used by Alembic. +revision: str = "b011fca27a94" +down_revision: Union[str, None] = "fbf2dd38133d" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("trajectory", "some_new_field", schema="gps") + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "trajectory", + sa.Column("some_new_field", sa.VARCHAR(), autoincrement=False, nullable=True), + schema="gps", + ) + # ### end Alembic commands ### From 4337c6bc5271763a070bb1d86c741843f6e2af5b Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:12:29 -0400 Subject: [PATCH 21/48] woops --- .github/workflows/db-changes-var1.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 2976268..4216807 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -112,7 +112,7 @@ jobs: env: DATABASE_URL: ${{ env.DATABASE_URL }} run: | - git stash pop # get the last revision script + # git stash pop # get the last revision script alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" cat migrations/versions/test_new_changes_002.py From c435fe7146105dca84db9844104b47090f37b4cc Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:15:00 -0400 Subject: [PATCH 22/48] remove --- migrations/versions/test_02.py | 35 ---------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 migrations/versions/test_02.py diff --git a/migrations/versions/test_02.py b/migrations/versions/test_02.py deleted file mode 100644 index 9309894..0000000 --- a/migrations/versions/test_02.py +++ /dev/null @@ -1,35 +0,0 @@ -"""test_02 - -Revision ID: b011fca27a94 -Revises: fbf2dd38133d -Create Date: 2024-09-06 12:10:34.691538 - -""" - -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa -import geoalchemy2 - -# revision identifiers, used by Alembic. -revision: str = "b011fca27a94" -down_revision: Union[str, None] = "fbf2dd38133d" -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column("trajectory", "some_new_field", schema="gps") - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.add_column( - "trajectory", - sa.Column("some_new_field", sa.VARCHAR(), autoincrement=False, nullable=True), - schema="gps", - ) - # ### end Alembic commands ### From b71a8d908e94eda9f8c17b5b7077c979eff75b94 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:25:02 -0400 Subject: [PATCH 23/48] add to pr --- .github/workflows/db-changes-var1.yaml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 4216807..2554987 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -129,20 +129,13 @@ jobs: set -e # catch errors python migrations/test_migration.py - # - name: Checkout new branch - # id: checkout-new-branch - # run: | - # git config --global user.email "github-actions[bot]@users.noreply.github.com" - # git config --global user.name "github-actions[bot]" - # git checkout -b ${{ env.BRANCH_NAME }} - # git push origin ${{ env.BRANCH_NAME }} - # - name: Add alembic script to new branch - # id: add-alembic-script-to-new-branch - # run: | - # git add . - # git commit -m "Add new Alembic migration" - # git push origin HEAD:${{ github.ref }} + - name: Add new alembic script to PR + id: add-alembic-script-to-new-branch + run: | + git add . + git commit -m "Add new Alembic migration" + git push origin HEAD:${{ github.ref }} # - name: Create PR # id: create-pull-request From 1af408e920a88fce3e1d86f5d71842f3e0f1658d Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:30:56 -0400 Subject: [PATCH 24/48] this? --- .github/workflows/db-changes-var1.yaml | 5 +---- alembic.ini | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 2554987..c70d5dc 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -132,10 +132,7 @@ jobs: - name: Add new alembic script to PR id: add-alembic-script-to-new-branch - run: | - git add . - git commit -m "Add new Alembic migration" - git push origin HEAD:${{ github.ref }} + uses: stefanzweifel/git-auto-commit-action@v5 # - name: Create PR # id: create-pull-request diff --git a/alembic.ini b/alembic.ini index ca596ca..f2ced43 100644 --- a/alembic.ini +++ b/alembic.ini @@ -91,17 +91,17 @@ keys = console keys = generic [logger_root] -level = DEBUG +level = WARN handlers = console qualname = [logger_sqlalchemy] -level = DEBUG +level = INFO handlers = qualname = sqlalchemy.engine [logger_alembic] -level = DEBUG +level = INFO handlers = qualname = alembic From e7455c2e89b8edafbf462eac1d35542f9bdceaad Mon Sep 17 00:00:00 2001 From: Erutis Date: Fri, 6 Sep 2024 16:31:47 +0000 Subject: [PATCH 25/48] Apply automatic changes --- migrations/versions/test_new_changes_002.py | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 migrations/versions/test_new_changes_002.py diff --git a/migrations/versions/test_new_changes_002.py b/migrations/versions/test_new_changes_002.py new file mode 100644 index 0000000..a672dfa --- /dev/null +++ b/migrations/versions/test_new_changes_002.py @@ -0,0 +1,30 @@ +"""test_new_changes_002 + +Revision ID: 2a72bfa70854 +Revises: fbf2dd38133d +Create Date: 2024-09-06 16:31:45.872306 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import geoalchemy2 + +# revision identifiers, used by Alembic. +revision: str = '2a72bfa70854' +down_revision: Union[str, None] = 'fbf2dd38133d' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = 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 ### From c4a388c111322421f8832720a83e6e23be2b3e6a Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:34:30 -0400 Subject: [PATCH 26/48] clean --- .github/workflows/db-changes-var1.yaml | 27 ++------------------------ 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index c70d5dc..97ecd75 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -81,13 +81,6 @@ jobs: python -m pip install --upgrade pip pip install -r app/requirements.txt - # - name: Run alembic script autogen for Initial DB Setup - # id: run-alembic-script-autogen - # env: - # DATABASE_URL: ${{ env.DATABASE_URL }} - # run: | - # alembic -c alembic.ini revision --autogenerate -m "test_temp_db_001" - - name: Alembic Upgrade Head id: run-alembic-upgrade-initial env: @@ -95,12 +88,6 @@ jobs: run: | alembic -c alembic.ini upgrade head - # - name: Git stash migration script for new branch checkout - # id: git-stash-migration-script - # run: | - # git add . - # git stash - - name: Checkout New Branch uses: actions/checkout@v4 with: @@ -112,9 +99,8 @@ jobs: env: DATABASE_URL: ${{ env.DATABASE_URL }} run: | - # git stash pop # get the last revision script - alembic -c alembic.ini revision --autogenerate -m "test_new_changes_002" - cat migrations/versions/test_new_changes_002.py + alembic -c alembic.ini revision --autogenerate -m "test_001" + cat migrations/versions/test_001.py - name: Upgrade alembic head with new revision id: run-alembic-upgrade-new @@ -134,12 +120,3 @@ jobs: id: add-alembic-script-to-new-branch uses: stefanzweifel/git-auto-commit-action@v5 - # - name: Create PR - # id: create-pull-request - # uses: peter-evans/create-pull-request@v5 - # with: - # branch: ${{ env.BRANCH_NAME }} - # base: main - # title: "BotPR: {{ env.BRANCH_NAME }}" - # author: "github-actions[bot] " - From 0a4aa5043f2a435422b8c7c72b4c1ec406e447c7 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:35:10 -0400 Subject: [PATCH 27/48] oops --- .github/workflows/db-changes-var1.yaml | 4 +-- migrations/versions/test_new_changes_002.py | 30 --------------------- 2 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 migrations/versions/test_new_changes_002.py diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 97ecd75..131e868 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -99,8 +99,8 @@ jobs: env: DATABASE_URL: ${{ env.DATABASE_URL }} run: | - alembic -c alembic.ini revision --autogenerate -m "test_001" - cat migrations/versions/test_001.py + alembic -c alembic.ini revision --autogenerate -m "test_002" + cat migrations/versions/test_002.py - name: Upgrade alembic head with new revision id: run-alembic-upgrade-new diff --git a/migrations/versions/test_new_changes_002.py b/migrations/versions/test_new_changes_002.py deleted file mode 100644 index a672dfa..0000000 --- a/migrations/versions/test_new_changes_002.py +++ /dev/null @@ -1,30 +0,0 @@ -"""test_new_changes_002 - -Revision ID: 2a72bfa70854 -Revises: fbf2dd38133d -Create Date: 2024-09-06 16:31:45.872306 - -""" -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa -import geoalchemy2 - -# revision identifiers, used by Alembic. -revision: str = '2a72bfa70854' -down_revision: Union[str, None] = 'fbf2dd38133d' -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = 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 ### From 3a86f35efada91028b3bbb1a1361e50ccf7f5986 Mon Sep 17 00:00:00 2001 From: Erutis Date: Fri, 6 Sep 2024 16:35:56 +0000 Subject: [PATCH 28/48] Apply automatic changes --- migrations/versions/test_002.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 migrations/versions/test_002.py diff --git a/migrations/versions/test_002.py b/migrations/versions/test_002.py new file mode 100644 index 0000000..6700a6f --- /dev/null +++ b/migrations/versions/test_002.py @@ -0,0 +1,30 @@ +"""test_002 + +Revision ID: 1b49801e38b7 +Revises: fbf2dd38133d +Create Date: 2024-09-06 16:35:54.989881 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import geoalchemy2 + +# revision identifiers, used by Alembic. +revision: str = '1b49801e38b7' +down_revision: Union[str, None] = 'fbf2dd38133d' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = 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 ### From 38dc16afc278f50d4bf4d68751d7c1c44d355e3c Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:35:56 -0400 Subject: [PATCH 29/48] nvm --- alembic.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alembic.ini b/alembic.ini index f2ced43..1650f47 100644 --- a/alembic.ini +++ b/alembic.ini @@ -101,7 +101,7 @@ handlers = qualname = sqlalchemy.engine [logger_alembic] -level = INFO +level = WARN handlers = qualname = alembic From b98f3443b59c0a57efd93755066bb37d542867ba Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:36:39 -0400 Subject: [PATCH 30/48] oop --- alembic.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alembic.ini b/alembic.ini index 1650f47..d8a0020 100644 --- a/alembic.ini +++ b/alembic.ini @@ -96,12 +96,12 @@ handlers = console qualname = [logger_sqlalchemy] -level = INFO +level = WARN handlers = qualname = sqlalchemy.engine [logger_alembic] -level = WARN +level = INFO handlers = qualname = alembic From ac3591b0af8ea22823ea189a83f4c460411b1b65 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:42:43 -0400 Subject: [PATCH 31/48] dafuq --- .github/workflows/db-changes-var1.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 131e868..e600a16 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -88,6 +88,12 @@ jobs: run: | alembic -c alembic.ini upgrade head + - name: Test DB is set up correctly on init + id: test-db-set-up-init + run: | + set -e # catch errors + python migrations/test_migration.py + - name: Checkout New Branch uses: actions/checkout@v4 with: @@ -109,7 +115,7 @@ jobs: run: | alembic -c alembic.ini upgrade head - - name: Test DB is set up correctly + - name: Test DB is still set up correctly id: test-db-set-up run: | set -e # catch errors From ec4a820567d1583f12fcfc87f88641f4201cf50e Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:43:28 -0400 Subject: [PATCH 32/48] dafuq --- .github/workflows/db-changes-var1.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index e600a16..84c99fb 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -122,7 +122,8 @@ jobs: python migrations/test_migration.py - - name: Add new alembic script to PR - id: add-alembic-script-to-new-branch - uses: stefanzweifel/git-auto-commit-action@v5 + # - name: Add new alembic script to PR + # id: add-alembic-script-to-new-branch + # uses: stefanzweifel/git-auto-commit-action@v5 + From 806769c407d249b9442e017c80b5b0576063eda7 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:48:56 -0400 Subject: [PATCH 33/48] fuck you dude --- migrations/versions/test_002.py | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 migrations/versions/test_002.py diff --git a/migrations/versions/test_002.py b/migrations/versions/test_002.py deleted file mode 100644 index 6700a6f..0000000 --- a/migrations/versions/test_002.py +++ /dev/null @@ -1,30 +0,0 @@ -"""test_002 - -Revision ID: 1b49801e38b7 -Revises: fbf2dd38133d -Create Date: 2024-09-06 16:35:54.989881 - -""" -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa -import geoalchemy2 - -# revision identifiers, used by Alembic. -revision: str = '1b49801e38b7' -down_revision: Union[str, None] = 'fbf2dd38133d' -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = 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 ### From 3ecebe32a28964f3fb3d479f11fc62ed3e1e1dc1 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:51:19 -0400 Subject: [PATCH 34/48] wow --- .github/workflows/db-changes-var1.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 84c99fb..9f16c98 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -100,6 +100,10 @@ jobs: fetch-depth: 0 ref: 'add-gha-auto-db-migration' + - name: git diff + run: | + git diff + - name: Generate alembic script for new branch id: run-alembic-script-autogen-round-2 env: From d86c52edee471e830df8202aa5926b387ff5354a Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 12:56:33 -0400 Subject: [PATCH 35/48] wuw --- migrations/env.py | 1 + 1 file changed, 1 insertion(+) diff --git a/migrations/env.py b/migrations/env.py index 87e545a..0f32fda 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -108,6 +108,7 @@ def run_migrations_online() -> None: dialect_opts={"paramstyle": "named"}, include_schemas=True, include_name=include_name, + transactional_ddl=False, ) with context.begin_transaction(): From 35f2869a9ad71602a29f18ae85a0fccb659a58e2 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 13:02:01 -0400 Subject: [PATCH 36/48] what do you want --- app/tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/tables.py b/app/tables.py index 3b9b680..e555254 100644 --- a/app/tables.py +++ b/app/tables.py @@ -68,4 +68,4 @@ class Trajectory(GISBase): __table_args__ = {"schema": "gps"} geom = mapped_column(Geometry("GEOMETRYZM", spatial_index=False)) feed_item_id = mapped_column(ForeignKey(FeedItem.id)) - some_new_field = mapped_column(String) + some_new_field_ERRRRR = mapped_column(String) From 745c8eb6b80a723894b39d214034ad07e0d139a0 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:28:45 -0400 Subject: [PATCH 37/48] how bout dis --- .github/workflows/db-changes-var1.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 9f16c98..15a0f22 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -100,9 +100,10 @@ jobs: fetch-depth: 0 ref: 'add-gha-auto-db-migration' - - name: git diff + - name: Fetch Main Branch run: | - git diff + git fetch origin main # Fetch the latest changes from main + git merge origin/main # Merge main branch into current branch - name: Generate alembic script for new branch id: run-alembic-script-autogen-round-2 From c542eab76c7ed7c6d6570d6d60f452b8a8fd400a Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:31:12 -0400 Subject: [PATCH 38/48] what if this makes it fail --- migrations/env.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/env.py b/migrations/env.py index 0f32fda..75f8229 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -17,7 +17,7 @@ if config.config_file_name is not None: fileConfig(config.config_file_name) - +# what if # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel From f9a3a9c36f82eb94532cdd5daf3dfbe265e24e10 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:32:33 -0400 Subject: [PATCH 39/48] aight --- migrations/env.py | 1 - 1 file changed, 1 deletion(-) diff --git a/migrations/env.py b/migrations/env.py index 75f8229..654110f 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -17,7 +17,6 @@ if config.config_file_name is not None: fileConfig(config.config_file_name) -# what if # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel From ea60470d2ff49da3bbd8b230ef34f600e7da99a4 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:35:22 -0400 Subject: [PATCH 40/48] ooh let's try dis --- .github/workflows/db-changes-var1.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 15a0f22..8027836 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -127,6 +127,13 @@ jobs: python migrations/test_migration.py + - name: Confirm schema is correct + run: | + psql -h localhost -U postgres -d postgres -c "\dt" # List all tables + + env: + PGPASSWORD: postgres + # - name: Add new alembic script to PR # id: add-alembic-script-to-new-branch # uses: stefanzweifel/git-auto-commit-action@v5 From 1917dd5f9756b1c379cfb200a98f4a7897c185cf Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:38:34 -0400 Subject: [PATCH 41/48] ooh woow --- .github/workflows/db-changes-var1.yaml | 2 +- migrations/test_migration.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 8027836..bb5d753 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -129,7 +129,7 @@ jobs: - name: Confirm schema is correct run: | - psql -h localhost -U postgres -d postgres -c "\dt" # List all tables + psql -h localhost -U postgres -d postgres -c "\dt *.*" # List all tables env: PGPASSWORD: postgres diff --git a/migrations/test_migration.py b/migrations/test_migration.py index f8ccf75..79d9a9e 100644 --- a/migrations/test_migration.py +++ b/migrations/test_migration.py @@ -86,11 +86,11 @@ def create_sample_linestring(area): def retrieve_row(): """Retrieve recently created row.""" - q = select(FeedItem) + q = select(Trajectory) with session as s: - feed_items = s.execute(q).scalars().all() + trajs = s.execute(q).scalars().all() - print(f"Retrieved feed item: {feed_items}") + print(f"Retrieved feed item: {[traj for traj in trajs]}") if __name__ == "__main__": From 36469a04947734d52c97af2f4622c13ea029cd37 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:41:14 -0400 Subject: [PATCH 42/48] nightmare --- .github/workflows/db-changes-var1.yaml | 2 +- migrations/test_migration.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index bb5d753..5761c16 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -129,7 +129,7 @@ jobs: - name: Confirm schema is correct run: | - psql -h localhost -U postgres -d postgres -c "\dt *.*" # List all tables + psql -h localhost -U postgres -d postgres -c "\dt public.* gps.*" # List all tables env: PGPASSWORD: postgres diff --git a/migrations/test_migration.py b/migrations/test_migration.py index 79d9a9e..a6d6c2f 100644 --- a/migrations/test_migration.py +++ b/migrations/test_migration.py @@ -90,7 +90,7 @@ def retrieve_row(): with session as s: trajs = s.execute(q).scalars().all() - print(f"Retrieved feed item: {[traj for traj in trajs]}") + print(f"Retrieved feed item: {[[t.id for t in traj] for traj in trajs]}") if __name__ == "__main__": From 8fd2f141d5de4eaa4e3c89a0d4beebacab6ef32c Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:42:29 -0400 Subject: [PATCH 43/48] duh --- migrations/test_migration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/test_migration.py b/migrations/test_migration.py index a6d6c2f..ce4bec2 100644 --- a/migrations/test_migration.py +++ b/migrations/test_migration.py @@ -90,7 +90,7 @@ def retrieve_row(): with session as s: trajs = s.execute(q).scalars().all() - print(f"Retrieved feed item: {[[t.id for t in traj] for traj in trajs]}") + print(f"Retrieved feed item: {[traj.id for traj in trajs]}") if __name__ == "__main__": From 18ac1fc51635e226d76762c4f99c6db8477a12ad Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:44:58 -0400 Subject: [PATCH 44/48] woob --- .github/workflows/db-changes-var1.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 5761c16..90c7945 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -129,13 +129,13 @@ jobs: - name: Confirm schema is correct run: | - psql -h localhost -U postgres -d postgres -c "\dt public.* gps.*" # List all tables - + psql -h localhost -U postgres -d postgres -c "\dt public.*" + psql -h localhost -U postgres -d postgres -c "\dt gps.*" env: PGPASSWORD: postgres - # - name: Add new alembic script to PR - # id: add-alembic-script-to-new-branch - # uses: stefanzweifel/git-auto-commit-action@v5 + - name: Add new alembic script to PR + id: add-alembic-script-to-new-branch + uses: stefanzweifel/git-auto-commit-action@v5 From 3b14f966e425dd95840c1769bd8aeba20a5b0bad Mon Sep 17 00:00:00 2001 From: Erutis Date: Fri, 6 Sep 2024 18:45:47 +0000 Subject: [PATCH 45/48] Apply automatic changes --- migrations/versions/test_002.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 migrations/versions/test_002.py diff --git a/migrations/versions/test_002.py b/migrations/versions/test_002.py new file mode 100644 index 0000000..d0bf052 --- /dev/null +++ b/migrations/versions/test_002.py @@ -0,0 +1,32 @@ +"""test_002 + +Revision ID: a2fa8615269b +Revises: fbf2dd38133d +Create Date: 2024-09-06 18:45:45.549338 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +import geoalchemy2 + +# revision identifiers, used by Alembic. +revision: str = 'a2fa8615269b' +down_revision: Union[str, None] = 'fbf2dd38133d' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('trajectory', sa.Column('some_new_field_ERRRRR', sa.String(), nullable=True), schema='gps') + op.drop_column('trajectory', 'some_new_field', schema='gps') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('trajectory', sa.Column('some_new_field', sa.VARCHAR(), autoincrement=False, nullable=True), schema='gps') + op.drop_column('trajectory', 'some_new_field_ERRRRR', schema='gps') + # ### end Alembic commands ### From 3d9ab71e294c2fb51b382cdc26d5c3143be50a5a Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:49:20 -0400 Subject: [PATCH 46/48] hell yeah --- migrations/env.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/migrations/env.py b/migrations/env.py index 654110f..a3edf65 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -39,6 +39,12 @@ def process_revision_directives(context, revision, directives): script = directives[0] script.imports.add("import geoalchemy2") + if config.cmd_opts.autogenerate: + script = directives[0] + if script.upgrade_ops.is_empty(): + directives[:] = [] + print("No changes in schema detected.") + def include_object(obj, name, type_, reflected, compare_to): """ From 503c3d56af7c7b361a024649705b5451d8dcc87b Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:56:05 -0400 Subject: [PATCH 47/48] jhgugh --- .github/workflows/db-changes-var1.yaml | 6 +++-- migrations/versions/test_002.py | 32 -------------------------- 2 files changed, 4 insertions(+), 34 deletions(-) delete mode 100644 migrations/versions/test_002.py diff --git a/.github/workflows/db-changes-var1.yaml b/.github/workflows/db-changes-var1.yaml index 90c7945..67f61d9 100644 --- a/.github/workflows/db-changes-var1.yaml +++ b/.github/workflows/db-changes-var1.yaml @@ -1,4 +1,4 @@ -name: DB Change Check var1 - K +name: Auto DB Migration on: pull_request: @@ -13,6 +13,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + ref: - name: Check For Changes id: changed-db-files @@ -24,10 +25,11 @@ jobs: id: check-conditions run: | echo "DB_CHANGE=${{ steps.changed-db-files.outputs.any_changed }}" >> $GITHUB_ENV + echo $DB_CHANGE run-alembic: needs: check-sql-schema-changes - # if: ${{ needs.check-sql-schema-changes.DB_CHANGE == 'true' }} + if: ${{ needs.check-sql-schema-changes.DB_CHANGE == 'true' }} runs-on: ubuntu-latest services: diff --git a/migrations/versions/test_002.py b/migrations/versions/test_002.py deleted file mode 100644 index d0bf052..0000000 --- a/migrations/versions/test_002.py +++ /dev/null @@ -1,32 +0,0 @@ -"""test_002 - -Revision ID: a2fa8615269b -Revises: fbf2dd38133d -Create Date: 2024-09-06 18:45:45.549338 - -""" -from typing import Sequence, Union - -from alembic import op -import sqlalchemy as sa -import geoalchemy2 - -# revision identifiers, used by Alembic. -revision: str = 'a2fa8615269b' -down_revision: Union[str, None] = 'fbf2dd38133d' -branch_labels: Union[str, Sequence[str], None] = None -depends_on: Union[str, Sequence[str], None] = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('trajectory', sa.Column('some_new_field_ERRRRR', sa.String(), nullable=True), schema='gps') - op.drop_column('trajectory', 'some_new_field', schema='gps') - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('trajectory', sa.Column('some_new_field', sa.VARCHAR(), autoincrement=False, nullable=True), schema='gps') - op.drop_column('trajectory', 'some_new_field_ERRRRR', schema='gps') - # ### end Alembic commands ### From a9e38d4b0025bb62d96f6648be35ebe8520ae843 Mon Sep 17 00:00:00 2001 From: K Agajanian Date: Fri, 6 Sep 2024 14:56:36 -0400 Subject: [PATCH 48/48] iuh --- app/tables.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/tables.py b/app/tables.py index e555254..7a9b31e 100644 --- a/app/tables.py +++ b/app/tables.py @@ -68,4 +68,3 @@ class Trajectory(GISBase): __table_args__ = {"schema": "gps"} geom = mapped_column(Geometry("GEOMETRYZM", spatial_index=False)) feed_item_id = mapped_column(ForeignKey(FeedItem.id)) - some_new_field_ERRRRR = mapped_column(String)