Search code examples
mysqlgoogle-app-enginesessionauthenticationwebapp2

Google app engine - migrating website user table from datastore to mysql (CloudSQL)


Our company is in the process of migrating our Google App Engine website's data from Google Cloud Datastore to mysql (CloudSQL to be precise)

I have written all the conversion routines to copy all of the current data entity tables from datastore to mysql and I am at the point where the code in our repos needs rewriting to interact with mysql instead of datastore.

Pretty much all of the current datastore entities subclass ndb.Model apart from one key table, our User entities which subclass from webapp2_extras.appengine.auth.models.User.

Subclassing from this does a lot of nice things behind the scenes such as setting up Unique and UserToken entries as well as setting up and taking care of sessions, setting them up when a user logs in and destroying them when a user logs out.

Now that the user table will live in mysql all these niceties that datastore was providing will need implementing separately and I am at a loss where to start.

What would be the best way to achieve this?

The site uses Google App Engine Standard Environment using the Python 2.7 runtime with webapp2 framework. I am using SqlAlchemy to interact with the mysql instance in the backend.

Any help or advice on this would be greatly appreciated and please let me know if you need any further specifics.


Solution

  • Searching around the webapp2 docs I found this information.

    http://webapp2.readthedocs.io/en/latest/tutorials/auth.html#login-with-sessions

    I did a little poking in the google SDK to see the same interface methods setup within webapp2_extras.appengine.auth.models.User.

    I created an AuthModel interface with the basic properties webapp2 would need to create a session and I implemented the methods described on the page. The methods call the SqlAlchemy query which would in turn interact with the SqlAlchemy User class I had set up and allow me to return the parameters needed for webapp2 and GAE to do the rest.