-- Generated by Ora2Pg, the Oracle database Schema converter, version 23.2.1
-- Copyright 2000-2022 Gilles DAROLD. All rights reserved.
-- DATASOURCE: dbi:Oracle:host=localhost;sid=NORMATIV;port=1521

SET client_encoding TO 'UTF8';

\set ON_ERROR_STOP ON

CREATE SCHEMA IF NOT EXISTS postgres_user;
ALTER SCHEMA postgres_user OWNER TO postgres_user;

SET search_path = postgres_user,public;


CREATE TABLE console_log_table (
	id bigint GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 MAXVALUE 9223372036854775807 MINVALUE 1 NO CYCLE CACHE 20 ),
	level_ integer NOT NULL DEFAULT 0,
	message varchar(1024),
	created timestamp NOT NULL DEFAULT statement_timestamp()
) ;
COMMENT ON TABLE console_log_table IS E'Таблица для хранения текста сообщений из console.log';
COMMENT ON COLUMN console_log_table.created IS E'Дата и время создания сообщения';
COMMENT ON COLUMN console_log_table.id IS E'Внутренний системный номер строки';
COMMENT ON COLUMN console_log_table.level_ IS E'Уровень логгинга, к которому относится данное сообщение';
CREATE INDEX console_log_table_created_idx ON console_log_table ((date_trunc('day', created)));
ALTER TABLE console_log_table ADD PRIMARY KEY (id);
ALTER TABLE console_log_table ALTER COLUMN CREATED SET NOT NULL;
ALTER TABLE console_log_table ADD CONSTRAINT console_log_table_level_chk CHECK (level_ in (100, 200, 300, 400, 500, 600, 128000));
ALTER TABLE console_log_table ALTER COLUMN LEVEL_ SET NOT NULL;
ALTER TABLE console_log_table ALTER COLUMN ID SET NOT NULL;


CREATE TABLE customers (
	id bigint GENERATED ALWAYS AS IDENTITY (START WITH 2 INCREMENT BY 1 MAXVALUE 9223372036854775807 MINVALUE 1 NO CYCLE CACHE 20 ),
	name varchar(32) NOT NULL,
	description varchar(512),
	status varchar(8) NOT NULL DEFAULT 'ACTIVE',
	created timestamp DEFAULT statement_timestamp()
) ;
COMMENT ON TABLE customers IS E'Таблица для хранения информации о клиентах';
COMMENT ON COLUMN customers.created IS E'Дата создания записи';
COMMENT ON COLUMN customers.description IS E'Описание клиента';
COMMENT ON COLUMN customers.id IS E'Внутренний системный номер строки';
COMMENT ON COLUMN customers.name IS E'Имя клиента';
COMMENT ON COLUMN customers.status IS E'Статус клиента';
ALTER TABLE customers ALTER COLUMN NAME SET NOT NULL;
ALTER TABLE customers ADD CONSTRAINT customers_status_chk CHECK (status in ('ACTIVE', 'HOLD', 'DELETED'));
ALTER TABLE customers ALTER COLUMN STATUS SET NOT NULL;
ALTER TABLE customers ALTER COLUMN ID SET NOT NULL;
