Skip to content

Commit

Permalink
Enable type comparison and batch mode by default
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Nov 13, 2022
1 parent 095b0ec commit a3085b3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/flask_migrate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,26 @@ def get_template_directory(self):


class Migrate(object):
def __init__(self, app=None, db=None, directory='migrations', **kwargs):
def __init__(self, app=None, db=None, directory='migrations',
compare_type=True, render_as_batch=True, **kwargs):
self.configure_callbacks = []
self.db = db
self.directory = str(directory)
self.alembic_ctx_kwargs = kwargs
self.alembic_ctx_kwargs['compare_type'] = compare_type
self.alembic_ctx_kwargs['render_as_batch'] = render_as_batch
if app is not None and db is not None:
self.init_app(app, db, directory)

def init_app(self, app, db=None, directory=None, **kwargs):
def init_app(self, app, db=None, directory=None, compare_type=None,
render_as_batch=None, **kwargs):
self.db = db or self.db
self.directory = str(directory or self.directory)
self.alembic_ctx_kwargs.update(kwargs)
if compare_type is not None:
self.alembic_ctx_kwargs['compare_type'] = compare_type
if render_as_batch is not None:
self.alembic_ctx_kwargs['render_as_batch'] = render_as_batch
if not hasattr(app, 'extensions'):
app.extensions = {}
app.extensions['migrate'] = _MigrateConfig(
Expand Down
4 changes: 2 additions & 2 deletions tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
migrate = Migrate(app, db)
migrate = Migrate(app, db, compare_type=False)


class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
name = db.Column(db.String(256))


@app.cli.command()
Expand Down
2 changes: 1 addition & 1 deletion tests/app_compare_type1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
migrate = Migrate(app, db, compare_type=True)
migrate = Migrate(app, db)


class User(db.Model):
Expand Down
2 changes: 1 addition & 1 deletion tests/app_compare_type2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)
migrate = Migrate(app, db, compare_type=True)
migrate = Migrate(app, db)


class User(db.Model):
Expand Down

0 comments on commit a3085b3

Please sign in to comment.