Skip to content

Latest commit

 

History

History

mod16-cloudstorage

Module 16 - Migrate from App Engine blobstore to Cloud Storage

Migrations

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:

  1. Migrate from App Engine webapp2 to Flask
  2. Migrate from App Engine ndb to Cloud NDB
  3. 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.

Python compatibility

This app is fully Python 2-3 compatible. To do a Python 3 deployment of this app:

  1. Edit app.yaml by enabling/uncommenting the runtime: python39 line
  2. Delete all other lines in app.yaml and save
  3. Delete lib (if present) and appengine_config.py (neither used in Python 3)
  4. Deploy with gcloud app deploy

Backwards compatibility

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.