mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-04 16:28:23 +00:00
DB migration initial
This commit is contained in:
1 parent
30c3a435d6
commit
3bd281bea0
93 files changed
+8350
-34
No files matched your search
@@ -0,0 +1,8 @@
|
||||
create table mytable (
|
||||
id integer not null,
|
||||
status varchar(1) not null,
|
||||
order_id integer not null,
|
||||
constraint ck_mytable_status check (status in ('A','B')),
|
||||
constraint pk_mytable primary key (id)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
alter table mytable add constraint fk_mytable_order_id foreign key (order_id) references orders (id) on delete restrict on update restrict;
|
||||
create index ix_mytable_order_id on mytable (order_id);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
drop table mytable;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
drop index ix_mytable_order_id;
|
||||
alter table mytable drop constraint fk_mytable_order_id;
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
create table o_address (
|
||||
id bigint not null,
|
||||
line1 varchar(100),
|
||||
line2 varchar(100),
|
||||
city varchar(100),
|
||||
country_code varchar(2),
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint pk_o_address primary key (id)
|
||||
);
|
||||
|
||||
create table blob_holder (
|
||||
id bigint not null,
|
||||
text_content clob,
|
||||
binary_content blob,
|
||||
file_content blob,
|
||||
version bigint not null,
|
||||
constraint pk_blob_holder primary key (id)
|
||||
);
|
||||
|
||||
create table car_accessory (
|
||||
id bigint not null,
|
||||
name varchar(255),
|
||||
car_id bigint,
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint pk_car_accessory primary key (id)
|
||||
);
|
||||
|
||||
create table be_contact (
|
||||
id bigint not null,
|
||||
first_name varchar(50),
|
||||
last_name varchar(50),
|
||||
email varchar(200),
|
||||
phone varchar(20),
|
||||
customer_id bigint not null,
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint pk_be_contact primary key (id)
|
||||
);
|
||||
|
||||
create table contact_note (
|
||||
id bigint not null,
|
||||
contact_id bigint not null,
|
||||
title varchar(255),
|
||||
note clob,
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint pk_contact_note primary key (id)
|
||||
);
|
||||
|
||||
create table o_country (
|
||||
code varchar(2) not null,
|
||||
name varchar(60),
|
||||
constraint pk_o_country primary key (code)
|
||||
);
|
||||
|
||||
create table be_customer (
|
||||
id bigint not null,
|
||||
inactive boolean,
|
||||
name varchar(100),
|
||||
registered timestamp,
|
||||
comments varchar(1000),
|
||||
billing_address_id bigint,
|
||||
shipping_address_id bigint,
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint uq_be_customer_name unique (name),
|
||||
constraint pk_be_customer primary key (id)
|
||||
);
|
||||
|
||||
create table document (
|
||||
id bigint not null,
|
||||
title varchar(255),
|
||||
author varchar(255),
|
||||
content clob,
|
||||
version bigint not null,
|
||||
constraint pk_document primary key (id)
|
||||
);
|
||||
|
||||
create table mrole (
|
||||
id integer not null,
|
||||
role_name varchar(255),
|
||||
constraint pk_mrole primary key (id)
|
||||
);
|
||||
|
||||
create table mrole_muser (
|
||||
mrole_id integer not null,
|
||||
muser_id integer not null,
|
||||
constraint pk_mrole_muser primary key (mrole_id,muser_id)
|
||||
);
|
||||
|
||||
create table muser (
|
||||
id integer not null,
|
||||
user_name varchar(255),
|
||||
user_type_id integer,
|
||||
constraint pk_muser primary key (id)
|
||||
);
|
||||
|
||||
create table muser_type (
|
||||
id integer not null,
|
||||
name varchar(255),
|
||||
constraint pk_muser_type primary key (id)
|
||||
);
|
||||
|
||||
create table o_booking (
|
||||
id bigint not null,
|
||||
booking_date date,
|
||||
invoice_id bigint,
|
||||
constraint uq_o_booking_invoice_id unique (invoice_id),
|
||||
constraint pk_o_booking primary key (id)
|
||||
);
|
||||
|
||||
create table o_invoice (
|
||||
id bigint not null,
|
||||
invoice_date date,
|
||||
constraint pk_o_invoice primary key (id)
|
||||
);
|
||||
|
||||
create table o_order (
|
||||
id bigint not null,
|
||||
status varchar(1),
|
||||
order_date date,
|
||||
ship_date date,
|
||||
customer_id bigint,
|
||||
shipping_address_id bigint,
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint ck_o_order_status check (status in ('N','C','A','S')),
|
||||
constraint pk_o_order primary key (id)
|
||||
);
|
||||
|
||||
create table o_order_detail (
|
||||
id bigint not null,
|
||||
order_id bigint,
|
||||
order_qty integer,
|
||||
ship_qty integer,
|
||||
unit_price double,
|
||||
product_id bigint,
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint pk_o_order_detail primary key (id)
|
||||
);
|
||||
|
||||
create table o_product (
|
||||
id bigint not null,
|
||||
sku varchar(20),
|
||||
name varchar(255),
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
constraint pk_o_product primary key (id)
|
||||
);
|
||||
|
||||
create table truck_ref (
|
||||
id integer not null,
|
||||
something varchar(255),
|
||||
constraint pk_truck_ref primary key (id)
|
||||
);
|
||||
|
||||
create table vehicle (
|
||||
dtype varchar(3) not null,
|
||||
id bigint not null,
|
||||
license_number varchar(255),
|
||||
registration_date timestamp,
|
||||
version bigint not null,
|
||||
when_created timestamp not null,
|
||||
when_modified timestamp not null,
|
||||
truck_ref_id integer,
|
||||
capacity double,
|
||||
driver varchar(255),
|
||||
car_ref_id integer,
|
||||
constraint pk_vehicle primary key (id)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
drop table o_address;
|
||||
|
||||
drop table blob_holder;
|
||||
|
||||
drop table car_accessory;
|
||||
|
||||
drop table be_contact;
|
||||
|
||||
drop table contact_note;
|
||||
|
||||
drop table o_country;
|
||||
|
||||
drop table be_customer;
|
||||
|
||||
drop table document;
|
||||
|
||||
drop table mrole;
|
||||
|
||||
drop table mrole_muser;
|
||||
|
||||
drop table muser;
|
||||
|
||||
drop table muser_type;
|
||||
|
||||
drop table o_booking;
|
||||
|
||||
drop table o_invoice;
|
||||
|
||||
drop table o_order;
|
||||
|
||||
drop table o_order_detail;
|
||||
|
||||
drop table o_product;
|
||||
|
||||
drop table truck_ref;
|
||||
|
||||
drop table vehicle;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
create table foo (
|
||||
col1 varchar(4) not null,
|
||||
col2 varchar(30) not null,
|
||||
col3 varchar(30) not null,
|
||||
constraint pk_foo primary key (col1)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://ebean-orm.github.io/xml/ns/dbmigration http://ebean-orm.github.io/xml/ns/dbmigration-1.0.xsd">
|
||||
|
||||
<changeSet id="1">
|
||||
|
||||
<createTable name="ckey_detail">
|
||||
<column name="id" type="integer" primaryKey="true" identity="true"/>
|
||||
<column name="something" type="varchar(255)" />
|
||||
<column name="one_key" type="integer" />
|
||||
<column name="two_key" type="varchar(255)" />
|
||||
</createTable>
|
||||
|
||||
<createTable name="ckey_parent">
|
||||
<column name="one_key" type="integer" primaryKey="true" />
|
||||
<column name="two_key" type="varchar(255)" primaryKey="true" />
|
||||
<column name="name" type="varchar(255)" />
|
||||
<column name="assoc_id" type="integer" references="ckey_assoc.id"/>
|
||||
<column name="version" type="integer" notnull="true" />
|
||||
</createTable>
|
||||
|
||||
</changeSet>
|
||||
|
||||
</migration>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://ebean-orm.github.io/xml/ns/dbmigration http://ebean-orm.github.io/xml/ns/dbmigration-1.0.xsd">
|
||||
|
||||
<changeSet id="1">
|
||||
|
||||
<createTable name="foo" withHistory="true" tablespace="fooSpace" indexTablespace="fooIndexSpace" remarks="comment">
|
||||
<column name="col1" type="varchar(4)" notnull="true" primaryKey="true"/>
|
||||
<column name="col2" type="varchar(30)" notnull="true"/>
|
||||
<column name="col3" type="varchar(30)" notnull="true"/>
|
||||
</createTable>
|
||||
|
||||
<addColumn tableName="foo">
|
||||
<column name="added_to_foo" type="varchar(20)"/>
|
||||
</addColumn>
|
||||
|
||||
<dropColumn columnName="col2" tableName="foo"/>
|
||||
|
||||
</changeSet>
|
||||
|
||||
</migration>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://ebean-orm.github.io/xml/ns/dbmigration http://ebean-orm.github.io/xml/ns/dbmigration-1.0.xsd">
|
||||
|
||||
<changeSet id="1">
|
||||
|
||||
<sql>
|
||||
<apply>
|
||||
create table foo;
|
||||
</apply>
|
||||
<rollback>
|
||||
drop table if exists foo;
|
||||
</rollback>
|
||||
</sql>
|
||||
|
||||
<createTable name="dbmigration">
|
||||
<column name="application" type="varchar(30)" notnull="true"/>
|
||||
<column name="change_log" type="integer" notnull="true"/>
|
||||
<column name="change_set" type="integer" notnull="true"/>
|
||||
<column name="locked_by" type="varchar(30)"/>
|
||||
<column name="locked_at" type="timestamp"/>
|
||||
</createTable>
|
||||
|
||||
<createTable name="dbmigration_changeset">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="application" type="varchar(30)" notnull="true" references="dbmigration.application"/>
|
||||
<column name="change_log" type="integer" notnull="true"/>
|
||||
<column name="change_set" type="integer" notnull="true"/>
|
||||
<column name="run_at" type="timestamp" notnull="true"/>
|
||||
<column name="run_by" type="varchar(30)" notnull="true"/>
|
||||
<column name="run_ddl" type="clob"/>
|
||||
<column name="run_log" type="clob"/>
|
||||
</createTable>
|
||||
|
||||
<createTable name="hello_world" withHistory="true">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="name" type="varchar(20)" notnull="true"/>
|
||||
<column name="type" type="varchar(20)" notnull="true"/>
|
||||
<column name="description" type="varchar(20)" notnull="true"/>
|
||||
<uniqueConstraint columnNames="name,type"/>
|
||||
</createTable>
|
||||
|
||||
<addColumn tableName="hello_world">
|
||||
<column name="fooe" type="varchar(20)"/>
|
||||
</addColumn>
|
||||
|
||||
<dropColumn columnName="fooe" tableName="hello_world"/>
|
||||
|
||||
<createHistoryTable baseTable="hello_world"/>
|
||||
|
||||
<addForeignKey name="fk_hello_world_x" columns="x" references="asdsad.asd"/>
|
||||
|
||||
</changeSet>
|
||||
|
||||
</migration>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://ebean-orm.github.io/xml/ns/dbmigration http://ebean-orm.github.io/xml/ns/dbmigration-1.0.xsd">
|
||||
|
||||
<changeSet id="1">
|
||||
|
||||
<sql>
|
||||
<apply>
|
||||
create table foo;
|
||||
</apply>
|
||||
<rollback>
|
||||
drop table if exists foo;
|
||||
</rollback>
|
||||
</sql>
|
||||
|
||||
<createTable name="dbmigration">
|
||||
<column name="application" type="varchar(30)" notnull="true"/>
|
||||
<column name="change_log" type="integer" notnull="true"/>
|
||||
<column name="change_set" type="integer" notnull="true"/>
|
||||
<column name="locked_by" type="varchar(30)"/>
|
||||
<column name="locked_at" type="timestamp"/>
|
||||
</createTable>
|
||||
|
||||
<createTable name="dbmigration_changeset">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="application" type="varchar(30)" notnull="true" references="dbmigration.application"/>
|
||||
<column name="change_log" type="integer" notnull="true"/>
|
||||
<column name="change_set" type="integer" notnull="true"/>
|
||||
<column name="run_at" type="timestamp" notnull="true"/>
|
||||
<column name="run_by" type="varchar(30)" notnull="true"/>
|
||||
<column name="run_ddl" type="clob"/>
|
||||
<column name="run_log" type="clob"/>
|
||||
</createTable>
|
||||
|
||||
<createTable name="hello_world" withHistory="true">
|
||||
<column name="id" type="integer" primaryKey="true"/>
|
||||
<column name="name" type="varchar(20)" notnull="true"/>
|
||||
<column name="description" type="varchar(20)" notnull="true"/>
|
||||
</createTable>
|
||||
|
||||
<addColumn tableName="hello_world">
|
||||
<column name="fooe" type="varchar(20)"/>
|
||||
</addColumn>
|
||||
|
||||
<dropColumn columnName="fooe" tableName="hello_world"/>
|
||||
|
||||
<createHistoryTable baseTable="hello_world"/>
|
||||
|
||||
</changeSet>
|
||||
|
||||
</migration>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<applications xmlns="http://ebean-orm.github.io/xml/ns/dbmigration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://ebean-orm.github.io/xml/ns/dbmigration http://ebean-orm.github.io/xml/ns/dbmigration-1.0.xsd">
|
||||
|
||||
<application name="myapp" resourcePath="dbmigration/app1"/>
|
||||
|
||||
</applications>
|
||||
Reference in new issue
Block a user