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

Duplicates in migration #279

Closed
Maksim-Burtsev opened this issue Dec 19, 2022 · 4 comments
Closed

Duplicates in migration #279

Maksim-Burtsev opened this issue Dec 19, 2022 · 4 comments

Comments

@Maksim-Burtsev
Copy link

Im change CharField to DateTime and use aerich migrate

Migration file look like this:

async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE TIMESTAMPTZ USING "ogrn_data_reg"::TIMESTAMPTZ;
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE TIMESTAMPTZ USING "ogrn_data_reg"::TIMESTAMPTZ;
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE TIMESTAMPTZ USING "ogrn_data_reg"::TIMESTAMPTZ;
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE TIMESTAMPTZ USING "ogrn_data_reg"::TIMESTAMPTZ;
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE TIMESTAMPTZ USING "ogrn_data_reg"::TIMESTAMPTZ;"""

async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE VARCHAR(255) USING "ogrn_data_reg"::VARCHAR(255);
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE VARCHAR(255) USING "ogrn_data_reg"::VARCHAR(255);
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE VARCHAR(255) USING "ogrn_data_reg"::VARCHAR(255);
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE VARCHAR(255) USING "ogrn_data_reg"::VARCHAR(255);
        ALTER TABLE "company" ALTER COLUMN "ogrn_data_reg" TYPE VARCHAR(255) USING "ogrn_data_reg"::VARCHAR(255);"""

I removed duplocate and successfully make aerich upgrade.

Is it ok?

@long2ice
Copy link
Member

long2ice commented Dec 20, 2022

Strange, can you show yourr models?

@Maksim-Burtsev
Copy link
Author

Is enough model where i made changes?

from src.core.utils.models import BaseModel
from tortoise import fields

IDENTIFYING_COMPANY_FIELDS = {'inn', 'ogrn'}


class Company(BaseModel):
    COMPANY_TYPES = ("AB", "CD", "EF")

    type = fields.CharField(20, default=COMPANY_TYPES[2])

    sub_type = fields.CharField(max_length=255, null=True)

    name_full = fields.CharField(max_length=255, null=True)
    name_short = fields.CharField(max_length=255, null=True)
    inn = fields.CharField(max_length=255, null=True)
    ogrn = fields.CharField(max_length=255, null=True)
    ogrn_data_reg = fields.DatetimeField(null=True)
    director = fields.CharField(max_length=255, null=True)
    email = fields.CharField(max_length=255, null=True)
    legal_address = fields.CharField(max_length=255, null=True)

    okopf = fields.CharField(max_length=255, null=True)
    kpp = fields.CharField(max_length=255, null=True)

    phone = fields.CharField(max_length=255, null=True)

@mo-rijndael
Copy link

Can confirm this happens. I changed type of a few columns from Int to Decimal, and for each column Aerich repeated ALTER TABLE ... five times

@long2ice
Copy link
Member

fixed

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