klen / peewee_migrate

Simple migration engine for Peewee
MIT License
353 stars 86 forks source link

Exclude a model from migration? #235

Closed ReS4 closed 4 months ago

ReS4 commented 4 months ago

Is it possible to exclude some models from migration? For example, the BaseModel?

class PeeweeBaseModel(Model):
    class Meta:
        database = Config.web_db

class Settings(PeeweeBaseModel):
    setting_name = CharField(primary_key=True)
    setting_value = TextField()
    setting_type = CharField()
ReS4 commented 4 months ago

Is it possible to exclude some models from migration? For example, the BaseModel?

class PeeweeBaseModel(Model):
    class Meta:
        database = Config.web_db

class Settings(PeeweeBaseModel):
    setting_name = CharField(primary_key=True)
    setting_value = TextField()
    setting_type = CharField()

I went through the package code, and there is an ignore argument that you can pass to the Router class to exclude specific models:

router = Router(Config.web_db, migrate_dir="models/migrations", ignore=["peeweebasemodel"])

This package is great, but it lacks good documentation...

Xevion commented 4 days ago

Minor detail for those who don't like raw strings: You can do something like ignore=[models.BaseModel._meta.table_name] so that when changed, refactored or whatever, the tablename is stable.