Skip to content
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

Creates migration in dependencies directory #633

Closed
spapas opened this issue Jul 2, 2024 · 6 comments
Closed

Creates migration in dependencies directory #633

spapas opened this issue Jul 2, 2024 · 6 comments

Comments

@spapas
Copy link
Contributor

spapas commented Jul 2, 2024

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
Copy link

jefer94 commented Jul 2, 2024

@chrisclark
Copy link
Collaborator

Yep - I am addressing right now: #634

chrisclark added a commit that referenced this issue Jul 3, 2024
@chrisclark
Copy link
Collaborator

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
Copy link

jefer94 commented Jul 3, 2024

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
Copy link
Collaborator

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
Copy link

jefer94 commented Jul 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants