简体   繁体   中英

How to import or create loopback Access control related tables from memory datasource to mysql datasource in loopbackJS?

I am trying to create or import LoopbackJS AccessToken, ACL, RoleMapping, Role tables from default memory based datasource db to my MySQL datasource. I defined a model Customer which extends built-in User model. My files are as below

server/datasources.js

{
  "db": {
    "name": "db",
    "connector": "memory"
  },
  "accountDs": {
    "host": "nmrony.local",
    "port": 3306,
    "database": "loopback_experiments",
    "username": "admin",
    "password": "****",
    "name": "accountDs",
    "connector": "mysql"
  }
}

server/model-config.js

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ]
  },
  "AccessToken": {
    "dataSource": "accountDs",
    "public": false
  },
  "ACL": {
    "dataSource": "accountDs",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "accountDs",
    "public": false
  },
  "Role": {
    "dataSource": "accountDs",
    "public": false
  },
  "Account": {
    "dataSource": "accountDs",
    "public": true
  },
  "Customer": {
    "dataSource": "accountDs",
    "public": true
  }
}

and

common/models/customer.json

{
  "name": "Customer",
  "base": "User",
  "idInjection": true,
  "properties": {
    "accountNumber": {
      "type": "number"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": []
}

Which gives me Customer model fields are

{
  "accountNumber": 0,
  "realm": "",
  "username": "",
  "credentials": "object",
  "challenges": "object",
  "email": "",
  "emailVerified": false,
  "verificationToken": "",
  "status": "",
  "created": "",
  "lastUpdated": "",
  "id": 0
}

How can I import or create customer and All ACL, Role related tables and accesstoken table in my mysql database? In fact I don't want to use built-in memory datasource at all.

you'd better to change following.

common/models/customer.json

{
  "name": "Customer",
  "base": "User",
  "idInjection": true,
  "options" : {
     "mysql" : {
       "schema": "myapp",
       "table": "user"
     }
  }
  "properties": {
    "accountNumber": {
      "type": "number"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": []
}

and put acl.json, role.json, rolemapping.json like above format with "options".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM