-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding linting to migrations #4874
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c85e11a
Adding linting to migrations
kevgliss fafd35d
Making it more reliable
kevgliss add70fb
Adding trigger
kevgliss 93bd46d
Adding dummy key
kevgliss feacf6b
More dummy vars
kevgliss bfc6924
Removing need for live database
kevgliss 6ec89df
Timeouts handled globally
kevgliss 84fa058
Only run if there are migrations
kevgliss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,60 @@ | ||
name: Eugene CI check | ||
|
||
on: pull_request | ||
|
||
env: | ||
EUGENE_VERSION: "0.6.1" | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
lint-migration: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.11.2 | ||
- uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Install python dependencies | ||
run: | | ||
export DISPATCH_LIGHT_BUILD=1 | ||
python -m pip install --upgrade pip | ||
pip install -e ".[dev]" | ||
- name: Download eugene | ||
run: | | ||
curl -L https://github.com/kaaveland/eugene/releases/download/$EUGENE_VERSION/eugene-x86_64-unknown-linux-musl -o eugene | ||
chmod +x eugene | ||
- name: Generate sql files | ||
run: | | ||
export LOG_LEVEL="ERROR" | ||
export STATIC_DIR="" | ||
export DATABASE_HOSTNAME="localhost" | ||
export DATABASE_CREDENTIALS="dispatch:dispatch" | ||
export DISPATCH_ENCRYPTION_KEY="NJHDWDJ3PbHT8h" | ||
export DISPATCH_JWT_SECRET="foo" | ||
|
||
changed_files=$(git diff --name-only -- src/dispatch/database/revisions/tenant/versions) | ||
if [ -z "$changed_files" ]; then | ||
echo "No migration files changed, skipping linting" | ||
exit 0 | ||
fi | ||
dispatch database upgrade --revision-type tenant --sql | ||
- name: Lint files | ||
run: ./eugene lint --ignore E9 alembic_output.sql -f md --accept-failures > lint.md | ||
- name: Post Comment | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
COMMENT=$(cat lint.md) | ||
gh pr comment ${{ github.event.pull_request.number }} --body "$COMMENT" |
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -396,6 +396,8 @@ def drop_database(yes): | |||||
def upgrade_database(tag, sql, revision, revision_type): | ||||||
"""Upgrades database schema to newest version.""" | ||||||
import sqlalchemy | ||||||
from contextlib import redirect_stdout | ||||||
|
||||||
from alembic import command as alembic_command | ||||||
from alembic.config import Config as AlembicConfig | ||||||
from sqlalchemy import inspect | ||||||
|
@@ -405,32 +407,41 @@ def upgrade_database(tag, sql, revision, revision_type): | |||||
from .database.manage import init_database | ||||||
|
||||||
alembic_cfg = AlembicConfig(config.ALEMBIC_INI_PATH) | ||||||
path = None | ||||||
if revision_type: | ||||||
if revision_type == "core": | ||||||
path = config.ALEMBIC_CORE_REVISION_PATH | ||||||
|
||||||
if not database_exists(str(config.SQLALCHEMY_DATABASE_URI)): | ||||||
click.secho("Found no database to upgrade, initializing new database...") | ||||||
init_database(engine) | ||||||
else: | ||||||
conn = engine.connect() | ||||||
|
||||||
# detect if we need to convert to a multi-tenant schema structure | ||||||
schema_names = inspect(engine).get_schema_names() | ||||||
if "dispatch_core" not in schema_names: | ||||||
click.secho("Detected single tenant database, converting to multi-tenant...") | ||||||
conn.execute(sqlalchemy.text(open(config.ALEMBIC_MULTI_TENANT_MIGRATION_PATH).read())) | ||||||
elif revision_type == "tenant": | ||||||
path = config.ALEMBIC_TENANT_REVISION_PATH | ||||||
|
||||||
if revision_type: | ||||||
if revision_type == "core": | ||||||
path = config.ALEMBIC_CORE_REVISION_PATH | ||||||
alembic_cfg.set_main_option("script_location", path) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
elif revision_type == "tenant": | ||||||
path = config.ALEMBIC_TENANT_REVISION_PATH | ||||||
# doesn't support core and tenant at the same time | ||||||
if sql: | ||||||
with open("alembic_output.sql", "w") as sql_file: | ||||||
with redirect_stdout(sql_file): | ||||||
alembic_command.upgrade(alembic_cfg, revision, sql=sql, tag=tag) | ||||||
|
||||||
alembic_cfg.set_main_option("script_location", path) | ||||||
alembic_command.upgrade(alembic_cfg, revision, sql=sql, tag=tag) | ||||||
else: | ||||||
if not database_exists(str(config.SQLALCHEMY_DATABASE_URI)): | ||||||
click.secho("Found no database to upgrade, initializing new database...") | ||||||
init_database(engine) | ||||||
else: | ||||||
for path in [config.ALEMBIC_CORE_REVISION_PATH, config.ALEMBIC_TENANT_REVISION_PATH]: | ||||||
alembic_cfg.set_main_option("script_location", path) | ||||||
conn = engine.connect() | ||||||
|
||||||
# detect if we need to convert to a multi-tenant schema structure | ||||||
schema_names = inspect(engine).get_schema_names() | ||||||
if "dispatch_core" not in schema_names: | ||||||
click.secho("Detected single tenant database, converting to multi-tenant...") | ||||||
conn.execute(sqlalchemy.text(open(config.ALEMBIC_MULTI_TENANT_MIGRATION_PATH).read())) | ||||||
|
||||||
if path: | ||||||
alembic_command.upgrade(alembic_cfg, revision, sql=sql, tag=tag) | ||||||
else: | ||||||
for path in [config.ALEMBIC_CORE_REVISION_PATH, config.ALEMBIC_TENANT_REVISION_PATH]: | ||||||
alembic_cfg.set_main_option("script_location", path) | ||||||
alembic_command.upgrade(alembic_cfg, revision, sql=sql, tag=tag) | ||||||
|
||||||
click.secho("Success.", fg="green") | ||||||
|
||||||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the playwright tests are failing since the
path
is stillNone
and lineset_main_option
in line 418 requires a string.