############################################################################
# Copyright 2021 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.
############################################################################


# pg secret
# pg init secret
---
apiVersion: v1
kind: Secret
metadata:
  name: mepm-db-init-sql
  labels:
    app: mepm-db-init-sql
type: Opaque
stringData:
  init.sql: |-
    CREATE USER lcmcontroller WITH PASSWORD '{{ .Values.mepm.postgres.lcmcontrollerDbPass }}' CREATEDB;
    CREATE DATABASE lcmcontrollerdb WITH OWNER = lcmcontroller
                                     ENCODING = 'UTF8'
                                     LC_COLLATE = 'en_US.utf8'
                                     LC_CTYPE = 'en_US.utf8'
                                     TABLESPACE = pg_default
                                     CONNECTION LIMIT = -1;
    CREATE TABLE edge_authenticate_rec (
                                     authenticate_id VARCHAR ( 64 ) PRIMARY KEY,
                                     name VARCHAR ( 255 ) NOT NULL,
                                     key VARCHAR ( 255 ) NOT NULL);
    GRANT ALL PRIVILEGES ON TABLE edge_authenticate_rec TO lcmcontroller;
    INSERT INTO edge_authenticate_rec (authenticate_id, name, key) VALUES ('39937079-99fe-4cd8-881f-04ca8c4fe09d', 'admin', '');

    CREATE USER k8splugin WITH PASSWORD '{{ .Values.mepm.postgres.k8spluginDbPass }}' CREATEDB;
    CREATE DATABASE k8splugindb WITH OWNER = k8splugin
                                     ENCODING = 'UTF8'
                                     LC_COLLATE = 'en_US.utf8'
                                     LC_CTYPE = 'en_US.utf8'
                                     TABLESPACE = pg_default
                                     CONNECTION LIMIT = -1;
    CREATE USER osplugin WITH PASSWORD '{{ .Values.mepm.postgres.ospluginDbPass }}' CREATEDB;
    CREATE DATABASE osplugindb WITH OWNER = osplugin
                                     ENCODING = 'UTF8'
                                     LC_COLLATE = 'en_US.utf8'
                                     LC_CTYPE = 'en_US.utf8'
                                     TABLESPACE = pg_default
                                     CONNECTION LIMIT = -1; 
   
    CREATE USER apprulemgr WITH PASSWORD '{{ .Values.mepm.postgres.apprulemgrDbPass }}' CREATEDB;
    CREATE DATABASE apprulemgrdb WITH OWNER = apprulemgr
                                     ENCODING = 'UTF8'
                                     LC_COLLATE = 'en_US.utf8'
                                     LC_CTYPE = 'en_US.utf8'
                                     TABLESPACE = pg_default
                                     CONNECTION LIMIT = -1;
                                     
    CREATE USER mepmtools WITH PASSWORD '{{ .Values.mepm.postgres.mepmtoolsDbPass }}' CREATEDB;
    CREATE DATABASE mepmtoolsdb WITH OWNER = mepmtools
                                     ENCODING = 'UTF8'
                                     LC_COLLATE = 'en_US.utf8'
                                     LC_CTYPE = 'en_US.utf8'
                                     TABLESPACE = pg_default
                                     CONNECTION LIMIT = -1;
