Skip to content

Example how to migrate the built-in User model to use MySQL instead of Memory db

Notifications You must be signed in to change notification settings

mikesparr/loopback-example-users-to-mysql

Repository files navigation

Loopback Example (MySQL)

The project is generated by LoopBack. I read about people wanting to use their own database for the built-in user model and decided to see how easy it would be to accomplish. I followed the instructions in https://github.com/strongloop/loopback-example-mysql and built the example from scratch, and then edited the User model.

How To Change Built-In User Model To MySQL Database

  • make sure you have the new MySQL datasource configured from tutorial
  • edit the /server/model-config.json file changing built-in models to your new DS
  • create the /server/bin/automigrate.js file (should be built from tutorial) and add automigrate() functions for each built-in Model
  • run > node server/bin/automigrate.js and you should see the following:
Your-Computer:loopback-example-mysql your-username$ node server/bin/automigrate.js 
User model migrated
ACL model migrated
AccessToken model migrated
Record created: { email: 'foo@bar.com',
  createdAt: Wed Jun 10 2015 08:29:10 GMT-0600 (MDT),
  lastModifiedAt: Wed Jun 10 2015 08:29:10 GMT-0600 (MDT),
  id: 2 }
Record created: { email: 'baz@qux.com',
  createdAt: Wed Jun 10 2015 08:29:10 GMT-0600 (MDT),
  lastModifiedAt: Wed Jun 10 2015 08:29:10 GMT-0600 (MDT),
  id: 1 }
done
Role model migrated
RoleMapping model migrated

If you check your database, you should now have the tables created and when you use the built-in localhost:3000/explorer app after starting the app, you can create users and they will appear in your database.

Kudos to the team at StrongLoop for building a nice framework and auto-scaffolding. I look forward to learning more and hopefully contributing as time permits.

About

Example how to migrate the built-in User model to use MySQL instead of Memory db

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published