explorerhq / sql-explorer

SQL reporting that Just Works. Fast, simple, and confusion-free. Write and share queries in a delightful SQL editor, with AI assistance.
https://www.sqlexplorer.io
Other
2.76k stars 366 forks source link

Creates migration in dependencies directory #633

Closed spapas closed 4 months ago

spapas commented 4 months ago

Hello, after installing the version 5.0.1 I get the following warning when running migrate:

  Your models in app(s): 'explorer' have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

When I run makemigrations it creates me a migration file in the dependency directory (i.e C:\progr\py3\ehcg\venv\Lib\site-packages\explorer\migrations). The migration file is 0019_alter_databaseconnection_engine.py with the following contents :


# Generated by Django 5.0.6 on 2024-07-02 06:55

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ("explorer", "0018_alter_databaseconnection_host_and_more"),
    ]

    operations = [
        migrations.AlterField(
            model_name="databaseconnection",
            name="engine",
            field=models.CharField(
                choices=[
                    ("django.db.backends.sqlite3", "SQLite3"),
                    ("django.db.backends.postgresql", "PostgreSQL"),
                    ("django.db.backends.mysql", "MySQL"),
                    ("django.db.backends.oracle", "Oracle"),
                    ("django.db.backends.mysql", "MariaDB"),
                    ("django_cockroachdb", "CockroachDB"),
                    ("django.db.backends.sqlserver", "SQL Server (mssql-django)"),
                ],
                max_length=255,
            ),
        ),
    ]

This is very problematic because when a new migration will be added to django-sql-explorer it will also get the number 19 and there will be a conflict. Can you please advise on how this situation should be handled ?

Thank you !

jefer94 commented 4 months ago

I have been getting the same error https://github.com/breatheco-de/apiv2/actions/runs/9757660712/job/26930572478?pr=1404

chrisclark commented 4 months ago

Yep - I am addressing right now: #634

chrisclark commented 4 months ago

Will be released in the next ~30 mins as 5.0.2 on pypi. Apologies for the oversight. I will also look to add a CI check to prevent this in the future.

jefer94 commented 4 months ago

I have this

.github/workflows/checks.yml


  migrations:
    needs: cache
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      # Cache Pipenv packages
      - name: Cache Pipenv packages
        uses: actions/cache@v2
        id: cache
        with:
          path: |
            ~/.local/share/virtualenvs
            ~/.cache/pip
          key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/Pipfile.lock') }}
          restore-keys: |
            ${{ runner.os }}-${{ env.PYTHON_VERSION }}-

      # Install Pipenv
      - name: Install dependencies
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          pip install pipenv

      - name: Check migrations
        run: |
          pipenv run python ./scripts/pending_migrations.py

scripts/pending_migrations.py

import os

p = os.system('python manage.py makemigrations --check --dry-run')

if p:
    exit(1)
chrisclark commented 4 months ago

Awesome, thanks! I'll get it integrated.

Why do you have the action call a python script that makes a bash call, vs just calling "makemigrations --check" directly in the yaml file?

jefer94 commented 4 months ago

Actually makemigrations --check returns a value different of 0 on error, you could use it directly in the checks.yml file