Create a database (schema/user) and a minimal set of DB object for a UnityBase ORM. Depending of then RDBMS -create switch force to execute a folowing SQL statements with DBA user permissions:

  • Oracle: CREATE USER ${databaseConfig.userID} and give a permissions;
  • Postgres: CREATE ROLE ${databaseConfig.userID} LOGIN PASSWORD '${databaseConfig.password}' VALID UNTIL 'infinity'; CREATE SCHEMA ${databaseConfig.userID} AUTHORIZATION ${databaseConfig.userID};
  • MS SQL: CREATE DATABASE ${databaseConfig.databaseName}; CREATE LOGIN ${databaseConfig.userID} WITH PASSWORD = N'${databaseConfig.password}

DBA can create a user/role/database manually, in this case -create parameter must be omitted.

Usage from a command line:

 ubcli initDB -?
 ubcli initDB -u admin -p admin -dba postgres -dbaPwd postgreDBAPassword

Usage from a code:

 const initDB = require('@unitybase/ubcli/initDB')
 let options = {
    host: 'http://localhost:888',
    user: 'admin',
    pwd: 'admin',
    clientIdentifier: 3,
    dropDatabase: true,
    createDatabase: true,
    dba: 'postgres',
    dbaPwd: 'postgreDBAPassword'
}
initDB(options)

Methods

# initDB (cfgobject) inner

Arguments:
  • cfg: object
    • clientIdentifier=3number

      Identifier of the client. Must be between 2 and 8999. Number 1 is for UnityBase developer, 3 for test. Numbers > 100 is for real installations

    • dropDatabaseboolean

      Drop a database/schema first

    • createDatabaseboolean

      Create a new database/schema.

    • dbastring

      A DBA name. Used in case createDatabase=true

    • dbaPwdstring

      A DBA password. Used in case createDatabase=true