############################################################################
# Copyright 2020 Huawei Technologies Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#  http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
############################################################################


apiVersion: v1
kind: ConfigMap
metadata:
  name: usermgmt-postgres-initdb-configmap
data:
  postgres.sql: |
    CREATE TABLE if not exists tbl_tenant (
      	TENANTID            VARCHAR(100)      PRIMARY KEY NOT NULL,
      	USERNAME            VARCHAR(50)       NOT NULL,
      	PASSWORD            VARCHAR(100)      NOT NULL,
      	COMPANY             VARCHAR(50)       NULL,
      	TELEPHONENUMBER     VARCHAR(20)       NULL,
        MAILADDRESS         VARCHAR(50)       NULL,
      	GENDER              VARCHAR(10)       NULL,
      	isallowed           boolean           NOT NULL,
      	CREATETIME          TIMESTAMP         NULL,
      	MODIFYTIME          TIMESTAMP         NULL,
        PWEFFECTTIME        TIMESTAMP         NULL,
      	CONSTRAINT USERNAME UNIQUE (username),
      	CONSTRAINT TELEPHONENUMBER UNIQUE (telephonenumber),
        CONSTRAINT MAILADDRESS UNIQUE (mailaddress)
    );

    CREATE TABLE if not exists tbl_tenant_role (
     	TENANTID            VARCHAR(100)      NOT NULL,
      	ROLEID              INTEGER           NOT NULL,
    primary key(TENANTID, ROLEID)
    );

    CREATE TABLE if not exists tbl_role (
    ID                   INTEGER                PRIMARY KEY NOT NULL,
    PLATFORM             VARCHAR(50)            NOT NULL,
    ROLE		         VARCHAR(50)            NOT NULL
    );

