-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how can i create tables User, AccessToken, ACL, RoleMapping, ROLE,... in Mysql #591
Comments
if you named Mysql datasource as "mysql" "mysql": {
"host": "localhost",
"port": 3306,
"database": "api",
"username": "root",
"password": "rootpassword",
"name": "mysql",
"connector": "mysql"
}, then what you need to use it as "dataSource" of User, AccessToken, ACL, RoleMapping, Role in /server/model-config.json, for example: "User": {
"dataSource": "mysql",
"public": true
},
"AccessToken": {
"dataSource": "mysql",
"public": false
},
"ACL": {
"dataSource": "mysql",
"public": false
},
"RoleMapping": {
"dataSource": "mysql",
"public": false
},
"Role": {
"dataSource": "mysql",
"public": false
}, then, to generate these tables, you could automigrate or for easier, use module grunt-loopback-auto. |
Thanks for your answer buy User, AccessToken ... already exists in explorer without creating the models. It comes with loopback by default. If i add like you suggest i have 2 User models in my explorer. |
You can use similar code as https://github.com/strongloop/loopback-example-database/blob/master/server/create-test-data.js#L15. The dataSource.automigrate(['User', 'Application', 'Role', 'ACL', 'RoleMapping, 'AccessToken'], function(err) {
...
}); If the models parameter is not present, all models will be applied. |
Thanks it works for me :). Just last question how can i change ROLE for USER model. I don't have user.json in my models list. I want to add something like this : "acls": [ ], |
Fixed thanks |
Can we customise the table names for built in models? For example I'd like to name the built in User model as users in my mysql database and AccessToken as access_tokens. I understand it can be done for custom models using model.json. Just wondering how to do it with built in models? |
@nivincp Seems to me that the only way to customize the name is to redefine the model. Hoping for another method. |
How do you create the default loopback model acls, roles, rolemapping etc. ? after using loopback autoupdate to create the array of default models, the values for User acls in the acls table were not created, in fact, only the model tables (with fields) were created, but no properties of the model were persisted (like acls). How can I achieve that? |
I'm experiencing the same thing as @danielmihai described. I can see the User, Role, RoleMapping tables on my mongodb datasource but the ACL, and AccessToken are not "migrated". Anybody figured this out? |
I made a boot script which does this on app startup. Take a look at the boot scripts in my loopback prototype repo if you'd like. I had to extend the basic User etc. models. Kind of ugly and imo defeats the scope of loopback |
Thanks @danielmihai your boot scripts gave me some ideas but I ended up just leaving ACL and AccessTokens in memory while the rest connected to a sql datasource. Works great so far. Do you guys see any issues with this approach? |
Probably it'll clear the data inside these tables if it's configured in memory after a script restart. |
Since the ACL and AccessTokens are in memory, I believe they are already automatically reset after every script restart. |
Started playing with Loopback and MySQL database and found that automigrate/autoupdate doesn't create relations between tables as well as ACL records for my models. I'm just wondering has anyone solved that somehow? I don't want to put this into the boot script as this makes usage of the relation generator and ACL generators kinda needless. |
I did it like that.
Daniel M. Colceag
… On 26 Feb 2017, at 18:48, Victor Kachan ***@***.***> wrote:
Started playing with Loopback and MySQL database and found that automigrate/autoupdate doesn't create relations between tables as well as ACL records for my models. I'm just wondering has anyone solved that somehow? I don't want to put this into the boot script as this makes usage of the relation generator and ACL generators kinda needless.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@danielmihai, I dived deep into the code of loopback-connector-mysql and I found that logic does not exist there, only creation of the tables. Thereby it seems like creation of the fk's and ACL records is a manual job :( |
I'm having this issue in loopback 3. I'm reviewing Daniel's solution but at first glance the API is loopback 2 (app.models(), etc) and it's postgresql. Here's what I'm seeing and here's the repro. The below code is my automigrate.js in /boot:
|
Has any solutions came up, or are going to have to manually recreate all the tables with our SQL DB. I am assuming the reason I can't login is because mySQL DB has no reference to the accessTokens? |
app.dataSources.mysqlDs.automigrate(['User', 'Application', 'Role', 'ACL', |
I want to use MySQL to manage Users. By default Loopback use DB dataSource. I have installed MySQL connector and all my custom models works good with mysql when i change datasource.
I want to use Mysql for Users model too. Do you have sql file with all schema for Users model?
Or there is automatic command can generate for me User, AccessToken, ACL, RoleMapping, ROLE,... tables.
Thanks
The text was updated successfully, but these errors were encountered: