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

How should an SQLite database migration file look like? #113

Open
revolter opened this issue Nov 7, 2018 · 4 comments
Open

How should an SQLite database migration file look like? #113

revolter opened this issue Nov 7, 2018 · 4 comments

Comments

@revolter
Copy link

revolter commented Nov 7, 2018

The documentation is very lacking so it's not clear at all.

Firstly, in the def migrate(migrator, database, fake=False, **kwargs): method, migrator is of type peewee_migrate.migrator.Migrator, so I have to use migrator.migrator to access the peewee_migrate.migrator.SqliteMigrator so it doesn't crashes. Is this the intended behavior?

Secondly, I'm using migrator.migrator.drop_not_null('user', 'username') and nothing is happening. Is drop_not_null supported or not?

@revolter
Copy link
Author

I successfully managed to get it working using:

from peewee import Model
from peewee_migrate import Migrator, Router
from playhouse.sqlite_ext import SqliteExtDatabase

database = SqliteExtDatabase('file_convert.sqlite')

database.connect()

migrator = Migrator(database)

router = Router(database)


class BaseModel(Model):
    class Meta:
        database = database


class User(BaseModel):
    ...

migrator.create_table(User) # The most important part

router.migrator = migrator
router.run()

@leosok
Copy link

leosok commented Nov 19, 2018

@revolter This would create a sqlite-database for me with just an empty migratehistory table. The logging says:

Starting migrations
There is nothing to migrate

Did you get it to do something useful?

@revolter
Copy link
Author

Take a look here for a complete, working example.

@ra0x3
Copy link

ra0x3 commented Sep 12, 2019

I managed to piece together examples by looking at the tests https://github.com/klen/peewee_migrate/tree/develop/tests

Would recommend the same to others, as documentation is sparse

Setup
Python 3.7.2 on Mojave

Dependencies

psycopg2==2.8.3
peewee==3.10.0
peewee-migrate==1.1.6

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