Skip to content

Commit a3085b3

Browse files
Enable type comparison and batch mode by default
1 parent 095b0ec commit a3085b3

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

src/flask_migrate/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,26 @@ def get_template_directory(self):
4242

4343

4444
class Migrate(object):
45-
def __init__(self, app=None, db=None, directory='migrations', **kwargs):
45+
def __init__(self, app=None, db=None, directory='migrations',
46+
compare_type=True, render_as_batch=True, **kwargs):
4647
self.configure_callbacks = []
4748
self.db = db
4849
self.directory = str(directory)
4950
self.alembic_ctx_kwargs = kwargs
51+
self.alembic_ctx_kwargs['compare_type'] = compare_type
52+
self.alembic_ctx_kwargs['render_as_batch'] = render_as_batch
5053
if app is not None and db is not None:
5154
self.init_app(app, db, directory)
5255

53-
def init_app(self, app, db=None, directory=None, **kwargs):
56+
def init_app(self, app, db=None, directory=None, compare_type=None,
57+
render_as_batch=None, **kwargs):
5458
self.db = db or self.db
5559
self.directory = str(directory or self.directory)
5660
self.alembic_ctx_kwargs.update(kwargs)
61+
if compare_type is not None:
62+
self.alembic_ctx_kwargs['compare_type'] = compare_type
63+
if render_as_batch is not None:
64+
self.alembic_ctx_kwargs['render_as_batch'] = render_as_batch
5765
if not hasattr(app, 'extensions'):
5866
app.extensions = {}
5967
app.extensions['migrate'] = _MigrateConfig(

tests/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1313

1414
db = SQLAlchemy(app)
15-
migrate = Migrate(app, db)
15+
migrate = Migrate(app, db, compare_type=False)
1616

1717

1818
class User(db.Model):
1919
id = db.Column(db.Integer, primary_key=True)
20-
name = db.Column(db.String(128))
20+
name = db.Column(db.String(256))
2121

2222

2323
@app.cli.command()

tests/app_compare_type1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1212

1313
db = SQLAlchemy(app)
14-
migrate = Migrate(app, db, compare_type=True)
14+
migrate = Migrate(app, db)
1515

1616

1717
class User(db.Model):

tests/app_compare_type2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1212

1313
db = SQLAlchemy(app)
14-
migrate = Migrate(app, db, compare_type=True)
14+
migrate = Migrate(app, db)
1515

1616

1717
class User(db.Model):

0 commit comments

Comments
 (0)