Giter Club home page Giter Club logo

peewee-moves's Introduction

peewee-moves

A simple and flexible migration manager for Peewee ORM.

Build Status

Code Coverage

Version

Downloads

Documentation

Requirements

  • python > 3.4, <= 3.8
  • peewee >= 3.0.0
  • click >= 2.0

Installation

This package can be installed using pip:

pip install peewee-moves

Usage

Here's a quick teaser of what you can do with peewee-moves:

$ export FLASK_APP=myflaskapp

$ flask db create app.models.Category
INFO: created migration 0001_create_table_category

$ flask db revision "do something"
INFO: created migration 0002_do_something

$ flask db upgrade
INFO: 0001_create_table_category: upgrade
INFO: 0002_do_something: upgrade

$ flask db downgrade
INFO: 0002_do_something: downgrade

$ flask db status
INFO: 0001_create_table_category: applied
INFO: 0002_do_something: pending

And if you're curious, here's what 0001_create_table_category.py looks like. A migration was automatically created based on the definition of the Category model.

def upgrade(migrator):
    with migrator.create_table('category') as table:
        table.primary_key('id')
        table.integer('code', unique=True)
        table.string('name', max_length=250)

def downgrade(migrator):
    migrator.drop_table('category')

Documentation

Check out the Full Documentation for more details.

peewee-moves's People

Contributors

arnulfojr avatar everhide avatar pylipp avatar revolter avatar timster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

peewee-moves's Issues

Run "Create" without changes breaks the code

When you create a migration for the first time it does it correctly. Then if you make changes somewhere and create the migration and update the database, the unmodified tables detect them as new.

Example:
 
Create the model (models.py):

class User (db.Model):
    username = CharField (unique = True)

class Tweet (db.Model):
    user = ForeignKeyField (User, backref = 'tweets')
    timestamp = DateTimeField (default = datetime.datetime.now)

Create the migration (console)
flask-db create app.models
and you get:
INFO: created: 0001_create_table_user
INFO: created: 0002_create_table_tweet

Apply the migration to the DB (console):
flask-db upgrade
and you get
INFO: all migrations applied!

Now, you want to make a change in the model (models.py)

class Tweet (db.Model):
    user = ForeignKeyField (User, backref = 'tweets')
    timestamp = DateTimeField (default = datetime.datetime.now)
    content = TextField ()

Create the new migration
flask-db create app.models
 and you get:
INFO: created: 0003_create_table_user
INFO: created: 0004_create_table_tweet

Apply new migration to the DB:
flask-db upgrade
and get
INFO: upgrade: 0003_create_table_user
ERROR: table "user" already exists

Feature: Fake migration

Hi @timster, thank you for your work, I really appreciate it!

We would like to include peewee-moves in our framework but we need a method to fake apply the migration in order to provide an easy way for the users to do the upgrade.

Please let me know what do you think and I would be glad to contribute with this feature.

Thank you!

Foreign-key field nullable not handled correctly

When trying to create a migration for a nullable ForeignKeyField , null=True does not appear in migration.

Eg:

  • model:
    purchase_request = ForeignKeyField(null=True, model=JumpPurchaseRequest, backref='jump_event')

  • migration:
    table.foreign_key('AUTO', 'purchase_request_id', on_delete=None, on_update=None, references='jump_purchase_request.id')

Thank you!

Click Package Requirement

Hi!

I'm using peewee-moves without Flask and upon importing the DatabaseManager, I'm getting an error about the missing package, Click at line 907.

Happy to put in a PR to add Click into the requirements.txt, but I wanted to get some feedback from @timster before doing so.

Thanks!

Support for peewee.TimestampField

Looks like the peewee.TimestampField isn't handled properly when creating migrations.

Steps to Reproduce:

Model:

from peewee import Model
from peewee import TimestampField
class Data(Model):
    timestamp = TimestampField(utc=True)
    class Meta(object):
        database = db

Resulting migration:

def upgrade(migrator):
    with migrator.create_table('data') as table:
        table.primary_key('id')
        table.timestamp('timestamp')

Correct migration:

peewee.TimestampField gets converted to int for all database backends.

def upgrade(migrator):
    with migrator.create_table('data') as table:
        table.primary_key('id')
        table.int('timestamp')

Resolution

I see you already have the mapping implemented, but either the target is wrong (change to peewee.TimestampField: 'int',) or the target is not created (TableCreator.timestamp).

New release to include the fakemodel_* index naming fix?

We've bumped into the same problem that was fixed in #9 but the latest release on PyPI doesn't include the fix. Could you make a new release so that the fix is included?

Thanks for your work. The lib has turned out to be very useful so far.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.