Skip to content

Commit a1baec9

Browse files
committed
🐛 fix(Alembic): Remove compare_type references
It's no longer required and indeed gives an error. Removed `compare_type` from lecture body and also from section 12 code.
1 parent b04aec7 commit a1baec9

File tree

25 files changed

+13
-204
lines changed

25 files changed

+13
-204
lines changed

docs/docs/11_deploy_to_render/05_environment_variables_and_migrations/README.md

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -193,114 +193,7 @@ class UserModel(db.Model):
193193

194194
### Running our migration with string length changes
195195

196-
Now we want to create a new migration so that our changes to the `UserModel` will be applied. But because we're changing the length of a string column, we need to first make a modification to the Alembic configuration.
197-
198-
The changes we want to make are to add `compare_type=True`[^alembic_docs] in both `context.configure()` calls:
199-
200-
```python title="migrations/env.py"
201-
from __future__ import with_statement
202-
203-
import logging
204-
from logging.config import fileConfig
205-
206-
from flask import current_app
207-
208-
from alembic import context
209-
210-
# this is the Alembic Config object, which provides
211-
# access to the values within the .ini file in use.
212-
config = context.config
213-
214-
# Interpret the config file for Python logging.
215-
# This line sets up loggers basically.
216-
fileConfig(config.config_file_name)
217-
logger = logging.getLogger('alembic.env')
218-
219-
# add your model's MetaData object here
220-
# for 'autogenerate' support
221-
# from myapp import mymodel
222-
# target_metadata = mymodel.Base.metadata
223-
config.set_main_option(
224-
'sqlalchemy.url',
225-
str(current_app.extensions['migrate'].db.get_engine().url).replace(
226-
'%', '%%'))
227-
target_metadata = current_app.extensions['migrate'].db.metadata
228-
229-
# other values from the config, defined by the needs of env.py,
230-
# can be acquired:
231-
# my_important_option = config.get_main_option("my_important_option")
232-
# ... etc.
233-
234-
235-
def run_migrations_offline():
236-
"""Run migrations in 'offline' mode.
237-
238-
This configures the context with just a URL
239-
and not an Engine, though an Engine is acceptable
240-
here as well. By skipping the Engine creation
241-
we don't even need a DBAPI to be available.
242-
243-
Calls to context.execute() here emit the given string to the
244-
script output.
245-
246-
"""
247-
url = config.get_main_option("sqlalchemy.url")
248-
context.configure(
249-
url=url,
250-
target_metadata=target_metadata,
251-
# highlight-start
252-
compare_type=True,
253-
# highlight-end
254-
literal_binds=True
255-
)
256-
257-
with context.begin_transaction():
258-
context.run_migrations()
259-
260-
261-
def run_migrations_online():
262-
"""Run migrations in 'online' mode.
263-
264-
In this scenario we need to create an Engine
265-
and associate a connection with the context.
266-
267-
"""
268-
269-
# this callback is used to prevent an auto-migration from being generated
270-
# when there are no changes to the schema
271-
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
272-
def process_revision_directives(context, revision, directives):
273-
if getattr(config.cmd_opts, 'autogenerate', False):
274-
script = directives[0]
275-
if script.upgrade_ops.is_empty():
276-
directives[:] = []
277-
logger.info('No changes in schema detected.')
278-
279-
connectable = current_app.extensions['migrate'].db.get_engine()
280-
281-
with connectable.connect() as connection:
282-
context.configure(
283-
connection=connection,
284-
target_metadata=target_metadata,
285-
process_revision_directives=process_revision_directives,
286-
# highlight-start
287-
compare_type=True,
288-
# highlight-end
289-
**current_app.extensions['migrate'].configure_args,
290-
)
291-
292-
with context.begin_transaction():
293-
context.run_migrations()
294-
295-
296-
if context.is_offline_mode():
297-
run_migrations_offline()
298-
else:
299-
run_migrations_online()
300-
301-
```
302-
303-
Next, let's create the new migration:
196+
Now we want to create a new migration so that our changes to the `UserModel` will be applied:
304197

305198
```bash
306199
flask db migrate

docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/end/app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from db import db
1111
from blocklist import BLOCKLIST
12-
import models
1312

1413
from resources.item import blp as ItemBlueprint
1514
from resources.store import blp as StoreBlueprint
@@ -97,10 +96,6 @@ def missing_token_callback(error):
9796
401,
9897
)
9998

100-
@app.before_first_request
101-
def create_tables():
102-
db.create_all()
103-
10499
api.register_blueprint(ItemBlueprint)
105100
api.register_blueprint(StoreBlueprint)
106101
api.register_blueprint(TagBlueprint)

docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/end/migrations/env.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def run_migrations_offline():
4848
context.configure(
4949
url=url,
5050
target_metadata=target_metadata,
51-
compare_type=True,
5251
literal_binds=True
5352
)
5453

@@ -81,8 +80,7 @@ def process_revision_directives(context, revision, directives):
8180
connection=connection,
8281
target_metadata=target_metadata,
8382
process_revision_directives=process_revision_directives,
84-
compare_type=True,
85-
**current_app.extensions['migrate'].configure_args
83+
**current_app.extensions['migrate'].configure_args
8684
)
8785

8886
with context.begin_transaction():

docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/start/app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from db import db
1111
from blocklist import BLOCKLIST
12-
import models
1312

1413
from resources.item import blp as ItemBlueprint
1514
from resources.store import blp as StoreBlueprint
@@ -97,10 +96,6 @@ def missing_token_callback(error):
9796
401,
9897
)
9998

100-
@app.before_first_request
101-
def create_tables():
102-
db.create_all()
103-
10499
api.register_blueprint(ItemBlueprint)
105100
api.register_blueprint(StoreBlueprint)
106101
api.register_blueprint(TagBlueprint)

docs/docs/12_task_queues_emails/01_send_emails_python_mailgun/start/migrations/env.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def run_migrations_offline():
4848
context.configure(
4949
url=url,
5050
target_metadata=target_metadata,
51-
compare_type=True,
5251
literal_binds=True
5352
)
5453

@@ -81,8 +80,7 @@ def process_revision_directives(context, revision, directives):
8180
connection=connection,
8281
target_metadata=target_metadata,
8382
process_revision_directives=process_revision_directives,
84-
compare_type=True,
85-
**current_app.extensions['migrate'].configure_args
83+
**current_app.extensions['migrate'].configure_args
8684
)
8785

8886
with context.begin_transaction():

docs/docs/12_task_queues_emails/02_send_email_user_registration/end/app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from db import db
1111
from blocklist import BLOCKLIST
12-
import models
1312

1413
from resources.item import blp as ItemBlueprint
1514
from resources.store import blp as StoreBlueprint
@@ -97,10 +96,6 @@ def missing_token_callback(error):
9796
401,
9897
)
9998

100-
@app.before_first_request
101-
def create_tables():
102-
db.create_all()
103-
10499
api.register_blueprint(ItemBlueprint)
105100
api.register_blueprint(StoreBlueprint)
106101
api.register_blueprint(TagBlueprint)

docs/docs/12_task_queues_emails/02_send_email_user_registration/end/migrations/env.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def run_migrations_offline():
4848
context.configure(
4949
url=url,
5050
target_metadata=target_metadata,
51-
compare_type=True,
5251
literal_binds=True
5352
)
5453

@@ -81,8 +80,7 @@ def process_revision_directives(context, revision, directives):
8180
connection=connection,
8281
target_metadata=target_metadata,
8382
process_revision_directives=process_revision_directives,
84-
compare_type=True,
85-
**current_app.extensions['migrate'].configure_args
83+
**current_app.extensions['migrate'].configure_args
8684
)
8785

8886
with context.begin_transaction():

docs/docs/12_task_queues_emails/02_send_email_user_registration/start/app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from db import db
1111
from blocklist import BLOCKLIST
12-
import models
1312

1413
from resources.item import blp as ItemBlueprint
1514
from resources.store import blp as StoreBlueprint
@@ -97,10 +96,6 @@ def missing_token_callback(error):
9796
401,
9897
)
9998

100-
@app.before_first_request
101-
def create_tables():
102-
db.create_all()
103-
10499
api.register_blueprint(ItemBlueprint)
105100
api.register_blueprint(StoreBlueprint)
106101
api.register_blueprint(TagBlueprint)

docs/docs/12_task_queues_emails/02_send_email_user_registration/start/migrations/env.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def run_migrations_offline():
4848
context.configure(
4949
url=url,
5050
target_metadata=target_metadata,
51-
compare_type=True,
5251
literal_binds=True
5352
)
5453

@@ -81,8 +80,7 @@ def process_revision_directives(context, revision, directives):
8180
connection=connection,
8281
target_metadata=target_metadata,
8382
process_revision_directives=process_revision_directives,
84-
compare_type=True,
85-
**current_app.extensions['migrate'].configure_args
83+
**current_app.extensions['migrate'].configure_args
8684
)
8785

8886
with context.begin_transaction():

docs/docs/12_task_queues_emails/04_populate_rq_task_queue/end/app.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from db import db
1111
from blocklist import BLOCKLIST
12-
import models
1312

1413
from resources.item import blp as ItemBlueprint
1514
from resources.store import blp as StoreBlueprint
@@ -97,10 +96,6 @@ def missing_token_callback(error):
9796
401,
9897
)
9998

100-
@app.before_first_request
101-
def create_tables():
102-
db.create_all()
103-
10499
api.register_blueprint(ItemBlueprint)
105100
api.register_blueprint(StoreBlueprint)
106101
api.register_blueprint(TagBlueprint)

0 commit comments

Comments
 (0)