This repo folder is the corresponding code to the Module 16 codelab. The tutorial STARTs with the Python 2 code in the Module 15 repo folder and leads developers through a set of migrations, culminating in the code in this folder. In addition to migrating to Cloud Storage, a few others are done to get from Modules 15 to 16... here is the complete list:
- Migrate from App Engine
webapp2
to Flask - Migrate from App Engine
ndb
to Cloud NDB - Migrate from App Engine
blobstore
to Cloud Storage
The reason why the web framework requires migration is because blobstore
has dependencies on webapp
and webapp2
, so we could not start directly from a Flask app.
This app is fully Python 2-3 compatible. To do a Python 3 deployment of this app:
- Edit
app.yaml
by enabling/uncommenting theruntime: python39
line - Delete all other lines in
app.yaml
and save - Delete
lib
(if present) andappengine_config.py
(neither used in Python 3) - Deploy with
gcloud app deploy
One catch with this migration is that blobstore
has a dependency on webapp
. By migrating to Cloud Storage, that dependency is not resolved because the app was also migrated from webapp2
(and webapp
) to Flask. In real life, there may not be an option to just discard all your data. The main.py
in this folder is for the easy situation where you can, replacing ndb.BlobKeyProperty
(for Blobstore files) with ndb.StringProperty
(for Cloud Storage files) in the data model.
For the rest of us, we may need main-migrate.py
, an alternative version of the application. The data model here maintains a ndb.BlobKeyProperty
for backwards-compatibility and creates a 4th field for the Cloud Storage filename (ndb.StringProperty
). Furthermore, an additional etl_visits()
function is required to consolidate files created with Blobstore and Cloud Storage without changing the HTML template.