mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-23 15:12:58 +00:00
Featur/dbmigration 3 (#1118)
* ADD: more test classes for Softdelete and History * update reference models after adding test classes * DbMigration:Improved History generation for sqlserver * FIX: When DB supports Sql2011 platform, we must not alter the history-table (as this is handled by DB itself) * DbMigration: When dropping a table, drop the sequence also. * DbMigration: dropColumn is handled by platformDdl now, as SqlServerDdl needs to delete dependent objects (default constraints...) first * FIX: DbMigration is not executed on history table * DbMigration: can drop comment now. * No effective code change: completed ObjectFactory / fixed imports * FIX: drop table comment * Committed the reference models
This commit is contained in:
1 parent
84d3578e33
commit
9a7646195c
60 files changed
+922
-45
No files matched your search
@@ -27,13 +27,46 @@ create table migtest_e_history (
|
||||
constraint pk_migtest_e_history primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_history2 (
|
||||
id serial not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_history2 primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_ref (
|
||||
id serial not null,
|
||||
constraint pk_migtest_e_ref primary key (id)
|
||||
);
|
||||
|
||||
create table migtest_e_softdelete (
|
||||
id serial not null,
|
||||
test_string varchar(255),
|
||||
constraint pk_migtest_e_softdelete primary key (id)
|
||||
);
|
||||
|
||||
create index ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
|
||||
create index ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
|
||||
alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict;
|
||||
create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
|
||||
|
||||
alter table migtest_e_history2 add column sys_period tstzrange not null default tstzrange(current_timestamp, null);
|
||||
create table migtest_e_history2_history(like migtest_e_history2);
|
||||
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
|
||||
|
||||
create or replace function migtest_e_history2_history_version() returns trigger as $$
|
||||
begin
|
||||
if (TG_OP = 'UPDATE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
|
||||
NEW.sys_period = tstzrange(current_timestamp,null);
|
||||
return new;
|
||||
elsif (TG_OP = 'DELETE') then
|
||||
insert into migtest_e_history2_history (sys_period,id, test_string) values (tstzrange(lower(OLD.sys_period), current_timestamp), OLD.id, OLD.test_string);
|
||||
return old;
|
||||
end if;
|
||||
end;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
create trigger migtest_e_history2_history_upd
|
||||
before update or delete on migtest_e_history2
|
||||
for each row execute procedure migtest_e_history2_history_version();
|
||||
|
||||
Reference in new issue
Block a user