initail migration
This commit is contained in:
82
db/migration/base/001.up.base.sql
Normal file
82
db/migration/base/001.up.base.sql
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
create domain dmn_code as text not null;
|
||||||
|
create domain dmn_money as numeric(22, 4);
|
||||||
|
create domain dmn_qty numeric(18, 6);
|
||||||
|
create domain dmn_rate as numeric(5, 2);
|
||||||
|
|
||||||
|
create function iif(condition boolean, true_result anyelement, false_result anyelement) returns anyelement
|
||||||
|
immutable
|
||||||
|
language sql
|
||||||
|
as
|
||||||
|
$$
|
||||||
|
SELECT CASE
|
||||||
|
WHEN condition THEN true_result
|
||||||
|
ELSE false_result
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE
|
||||||
|
OR REPLACE FUNCTION zllog()
|
||||||
|
RETURNS trigger
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$BODY$
|
||||||
|
BEGIN
|
||||||
|
if
|
||||||
|
(TG_OP = 'INSERT') then
|
||||||
|
if (new.zlins_dttm is null) then
|
||||||
|
new.zlins_dttm = current_timestamp;
|
||||||
|
END if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if
|
||||||
|
(TG_OP = 'UPDATE') then
|
||||||
|
if (new.zlupd_dttm is null) then
|
||||||
|
new.zlupd_dttm = current_timestamp;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$BODY$;
|
||||||
|
|
||||||
|
|
||||||
|
create table logdml
|
||||||
|
(
|
||||||
|
id bigint generated by default as identity
|
||||||
|
primary key,
|
||||||
|
opr text,
|
||||||
|
dttm timestamp with time zone default CURRENT_TIMESTAMP not null,
|
||||||
|
src_table text,
|
||||||
|
src_id bigint,
|
||||||
|
usr_id bigint,
|
||||||
|
msg text,
|
||||||
|
old_val jsonb,
|
||||||
|
new_val jsonb
|
||||||
|
);
|
||||||
|
|
||||||
|
create index ndx_logdml_dttm
|
||||||
|
on logdml (dttm);
|
||||||
|
|
||||||
|
create index ndx_logdml_dttm_desc
|
||||||
|
on logdml (dttm desc);
|
||||||
|
|
||||||
|
create index ndx_logdml_table
|
||||||
|
on logdml (src_table, src_id);
|
||||||
|
|
||||||
|
|
||||||
|
create table sykv
|
||||||
|
(
|
||||||
|
key text not null
|
||||||
|
primary key,
|
||||||
|
val text
|
||||||
|
);
|
||||||
|
|
||||||
|
create table symigrate
|
||||||
|
(
|
||||||
|
id bigint generated by default as identity
|
||||||
|
primary key,
|
||||||
|
tracking_name text,
|
||||||
|
dttm timestamp default CURRENT_TIMESTAMP,
|
||||||
|
last_script integer,
|
||||||
|
log text
|
||||||
|
);
|
||||||
24
db/migration/migrate.sh
Executable file
24
db/migration/migrate.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
read -p "Server [localhost] : " SERVER
|
||||||
|
SERVER=${SERVER:-localhost}
|
||||||
|
|
||||||
|
read -p "Veritabanı : $1" DB
|
||||||
|
DB=${DB:-$1}
|
||||||
|
|
||||||
|
read -p "Yeniden oluşturulsun mu? (E/H) [H] : " CREATE
|
||||||
|
CREATE=${CREATE:-H}
|
||||||
|
|
||||||
|
CREATESTR=""
|
||||||
|
DROPSTR=""
|
||||||
|
if [[ ${CREATE} =~ (E|e) ]]; then
|
||||||
|
CREATESTR="-create"
|
||||||
|
read -p "Eski mevcutsa silinsin mi? (E/H) [E] : " DROP
|
||||||
|
DROP=${DROP:-E}
|
||||||
|
if [[ ${DROP} =~ (E|e) ]]; then
|
||||||
|
DROPSTR="-drop-if-exists"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
migrater -folder ./base -db ${DB} -host ${SERVER} ${CREATESTR} ${DROPSTR} -password tayitkan -tracker base -migrate-table symigrate
|
||||||
|
# migrater -folder ./seed -db ${DB} -host ${SERVER} ${CREATESTR} ${DROPSTR} -password tayitkan -tracker seed -migrate-table symigrate
|
||||||
Reference in New Issue
Block a user