Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mikesparr/loopback-example-users-to-mysql

Example how to migrate the built-in User model to use MySQL instead of Memory db
https://github.com/mikesparr/loopback-example-users-to-mysql

Last synced: about 6 hours ago
JSON representation

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

Awesome Lists containing this project

README

        

# Loopback Example (MySQL)

The project is generated by [LoopBack](http://loopback.io). 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: '[email protected]',
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: '[email protected]',
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.