@vrplatform/kysely 1.3.45-stage.37579320177 → 1.3.45-stage.37585410751
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import { sql } from 'kysely';
|
|
3
|
+
|
|
4
|
+
export async function up<Database>(db: Kysely<Database>): Promise<void> {
|
|
5
|
+
await sql`
|
|
6
|
+
create function core.register_inserted_reservation_journal_operations()
|
|
7
|
+
returns trigger
|
|
8
|
+
language plpgsql
|
|
9
|
+
as $$
|
|
10
|
+
declare
|
|
11
|
+
target_action_id uuid;
|
|
12
|
+
begin
|
|
13
|
+
for target_action_id in
|
|
14
|
+
select distinct action_id from inserted_invalidations
|
|
15
|
+
where action_id is not null
|
|
16
|
+
order by action_id
|
|
17
|
+
loop
|
|
18
|
+
perform core.register_reservation_journal_operation(target_action_id);
|
|
19
|
+
end loop;
|
|
20
|
+
return null;
|
|
21
|
+
end;
|
|
22
|
+
$$
|
|
23
|
+
`.execute(db);
|
|
24
|
+
await sql`
|
|
25
|
+
drop trigger refresh_reservation_journal_invalidation_operation
|
|
26
|
+
on accounting.reservation_journal_invalidation
|
|
27
|
+
`.execute(db);
|
|
28
|
+
await sql`
|
|
29
|
+
create trigger refresh_reservation_journal_invalidation_operation
|
|
30
|
+
after update of action_id, applied_at
|
|
31
|
+
on accounting.reservation_journal_invalidation
|
|
32
|
+
for each row
|
|
33
|
+
execute function core.refresh_reservation_journal_invalidation_operation()
|
|
34
|
+
`.execute(db);
|
|
35
|
+
await sql`
|
|
36
|
+
create trigger register_inserted_reservation_journal_operations
|
|
37
|
+
after insert on accounting.reservation_journal_invalidation
|
|
38
|
+
referencing new table as inserted_invalidations
|
|
39
|
+
for each statement
|
|
40
|
+
execute function core.register_inserted_reservation_journal_operations()
|
|
41
|
+
`.execute(db);
|
|
42
|
+
await sql`
|
|
43
|
+
do $$
|
|
44
|
+
begin
|
|
45
|
+
if exists (select 1 from pg_roles where rolname = 'application') then
|
|
46
|
+
grant execute on function
|
|
47
|
+
core.register_inserted_reservation_journal_operations()
|
|
48
|
+
to application;
|
|
49
|
+
end if;
|
|
50
|
+
end;
|
|
51
|
+
$$
|
|
52
|
+
`.execute(db);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function down<Database>(db: Kysely<Database>): Promise<void> {
|
|
56
|
+
await sql`
|
|
57
|
+
drop trigger register_inserted_reservation_journal_operations
|
|
58
|
+
on accounting.reservation_journal_invalidation
|
|
59
|
+
`.execute(db);
|
|
60
|
+
await sql`
|
|
61
|
+
drop trigger refresh_reservation_journal_invalidation_operation
|
|
62
|
+
on accounting.reservation_journal_invalidation
|
|
63
|
+
`.execute(db);
|
|
64
|
+
await sql`
|
|
65
|
+
create trigger refresh_reservation_journal_invalidation_operation
|
|
66
|
+
after insert or update of action_id, applied_at
|
|
67
|
+
on accounting.reservation_journal_invalidation
|
|
68
|
+
for each row
|
|
69
|
+
execute function core.refresh_reservation_journal_invalidation_operation()
|
|
70
|
+
`.execute(db);
|
|
71
|
+
await sql`
|
|
72
|
+
drop function core.register_inserted_reservation_journal_operations()
|
|
73
|
+
`.execute(db);
|
|
74
|
+
}
|