· 8 years ago · Mar 21, 2018, 11:50 AM
1# --- Created by Ebean DDL
2# To stop Ebean DDL generation, remove this comment and start using Evolutions
3
4# --- !Ups
5
6create table activation_code (
7 id bigserial not null,
8 code varchar(255),
9 platform_user_id bigint not null,
10 expired_at bigint,
11 version bigint not null,
12 when_created timestamptz not null,
13 when_updated timestamptz not null,
14 constraint pk_activation_code primary key (id)
15);
16
17create table faq (
18 id bigserial not null,
19 status integer not null,
20 platform_user_id bigint not null,
21 question varchar(255) not null,
22 answer varchar(255) not null,
23 row_order integer not null,
24 type integer not null,
25 version bigint not null,
26 when_created timestamptz not null,
27 when_updated timestamptz not null,
28 constraint ck_faq_status check ( status in (0,1,2)),
29 constraint ck_faq_type check ( type in (0,1,2,3,4,5,6,7,8,9)),
30 constraint pk_faq primary key (id)
31);
32
33create table news (
34 id bigserial not null,
35 title varchar(255) not null,
36 platform_user_id bigint not null,
37 type integer not null,
38 status integer not null,
39 version bigint not null,
40 when_created timestamptz not null,
41 when_updated timestamptz not null,
42 constraint ck_news_type check ( type in (0,1,2,3,4)),
43 constraint ck_news_status check ( status in (0,1,2)),
44 constraint pk_news primary key (id)
45);
46
47create table news_content (
48 id bigserial not null,
49 news_id bigint not null,
50 row_order integer not null,
51 body varchar(255) not null,
52 type integer not null,
53 version bigint not null,
54 when_created timestamptz not null,
55 when_updated timestamptz not null,
56 constraint ck_news_content_type check ( type in (0,1)),
57 constraint pk_news_content primary key (id)
58);
59
60create table platform_user (
61 id bigserial not null,
62 client_id bigint,
63 adviser_id bigint,
64 mobile_phone varchar(255),
65 merchant_phone varchar(255),
66 is_active boolean default false not null,
67 passport varchar(255),
68 email varchar(255),
69 firstname_client varchar(255),
70 lastname_client varchar(255),
71 structurallevel bigint,
72 personalroyaltypoints float,
73 structuralroyalypoints float,
74 version bigint not null,
75 when_created timestamptz not null,
76 when_updated timestamptz not null,
77 constraint uq_platform_user_mobile_phone unique (mobile_phone),
78 constraint pk_platform_user primary key (id)
79);
80
81create table push_token (
82 id bigserial not null,
83 token varchar(255),
84 type integer,
85 platform_user_id bigint not null,
86 version bigint not null,
87 when_created timestamptz not null,
88 when_updated timestamptz not null,
89 constraint ck_push_token_type check ( type in (0,1)),
90 constraint pk_push_token primary key (id)
91);
92
93create table transaction_billing (
94 id bigserial not null,
95 platform_user_id bigint,
96 recipient_id bigint,
97 full_name varchar(255),
98 amount_in_cents bigint not null,
99 currency_id bigint not null,
100 comment varchar(2000),
101 is_success boolean default false not null,
102 transaction_type integer,
103 transaction_direction integer,
104 merchant_phone varchar(255),
105 version bigint not null,
106 when_created timestamptz not null,
107 when_updated timestamptz not null,
108 constraint ck_transaction_billing_transaction_type check ( transaction_type in (0,1,2)),
109 constraint ck_transaction_billing_transaction_direction check ( transaction_direction in (0,1)),
110 constraint pk_transaction_billing primary key (id)
111);
112
113create index ix_activation_code_id on activation_code (id);
114create index ix_faq_id on faq (id);
115create index ix_news_id on news (id);
116create index ix_news_content_id on news_content (id);
117create index ix_platform_user_id on platform_user (id);
118create index ix_push_token_id on push_token (id);
119create index ix_transaction_billing_id on transaction_billing (id);
120alter table activation_code add constraint fk_activation_code_platform_user_id foreign key (platform_user_id) references platform_user (id) on delete restrict on update restrict;
121create index ix_activation_code_platform_user_id on activation_code (platform_user_id);
122
123alter table faq add constraint fk_faq_platform_user_id foreign key (platform_user_id) references platform_user (id) on delete restrict on update restrict;
124create index ix_faq_platform_user_id on faq (platform_user_id);
125
126alter table news add constraint fk_news_platform_user_id foreign key (platform_user_id) references platform_user (id) on delete restrict on update restrict;
127create index ix_news_platform_user_id on news (platform_user_id);
128
129alter table news_content add constraint fk_news_content_news_id foreign key (news_id) references news (id) on delete restrict on update restrict;
130create index ix_news_content_news_id on news_content (news_id);
131
132alter table push_token add constraint fk_push_token_platform_user_id foreign key (platform_user_id) references platform_user (id) on delete restrict on update restrict;
133create index ix_push_token_platform_user_id on push_token (platform_user_id);
134
135alter table transaction_billing add constraint fk_transaction_billing_platform_user_id foreign key (platform_user_id) references platform_user (id) on delete restrict on update restrict;
136create index ix_transaction_billing_platform_user_id on transaction_billing (platform_user_id);
137
138
139# --- !Downs
140
141alter table if exists activation_code drop constraint if exists fk_activation_code_platform_user_id;
142drop index if exists ix_activation_code_platform_user_id;
143
144alter table if exists faq drop constraint if exists fk_faq_platform_user_id;
145drop index if exists ix_faq_platform_user_id;
146
147alter table if exists news drop constraint if exists fk_news_platform_user_id;
148drop index if exists ix_news_platform_user_id;
149
150alter table if exists news_content drop constraint if exists fk_news_content_news_id;
151drop index if exists ix_news_content_news_id;
152
153alter table if exists push_token drop constraint if exists fk_push_token_platform_user_id;
154drop index if exists ix_push_token_platform_user_id;
155
156alter table if exists transaction_billing drop constraint if exists fk_transaction_billing_platform_user_id;
157drop index if exists ix_transaction_billing_platform_user_id;
158
159drop table if exists activation_code cascade;
160
161drop table if exists faq cascade;
162
163drop table if exists news cascade;
164
165drop table if exists news_content cascade;
166
167drop table if exists platform_user cascade;
168
169drop table if exists push_token cascade;
170
171drop table if exists transaction_billing cascade;
172
173drop index if exists ix_activation_code_id;
174drop index if exists ix_faq_id;
175drop index if exists ix_news_id;
176drop index if exists ix_news_content_id;
177drop index if exists ix_platform_user_id;
178drop index if exists ix_push_token_id;
179drop index if exists ix_transaction_billing_id;