File: londiste_fkeys.sql

package info (click to toggle)
londiste-sql 3.8-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 576 kB
  • sloc: sql: 2,742; python: 309; makefile: 19; sh: 2
file content (93 lines) | stat: -rw-r--r-- 3,179 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

set log_error_verbosity = 'terse';
set client_min_messages = 'warning';

create table ref_1 (
    id int4 primary key,
    val text
);

create table ref_2 (
    id int4 primary key,
    ref int4 not null references ref_1,
    val text
);

create table ref_3 (
    id int4 primary key,
    ref2 int4 not null references ref_2,
    val text
);

select * from londiste.global_add_table('branch_set', 'public.ref_1');
select * from londiste.global_add_table('branch_set', 'public.ref_2');
select * from londiste.global_add_table('branch_set', 'public.ref_3');

select * from londiste.local_add_table('branch_set', 'public.ref_1');
select * from londiste.local_add_table('branch_set', 'public.ref_2');
select * from londiste.local_add_table('branch_set', 'public.ref_3');

select * from londiste.find_table_fkeys('public.ref_1');
select * from londiste.find_table_fkeys('public.ref_2');
select * from londiste.find_table_fkeys('public.ref_3');

select * from londiste.get_table_pending_fkeys('public.ref_2');

select * from londiste.get_valid_pending_fkeys('branch_set');

-- drop fkeys

select * from londiste.drop_table_fkey('public.ref_2', 'ref_2_ref_fkey');

select * from londiste.find_table_fkeys('public.ref_1');
select * from londiste.find_table_fkeys('public.ref_2');
select * from londiste.find_table_fkeys('public.ref_3');

select * from londiste.drop_table_fkey('public.ref_3', 'ref_3_ref2_fkey');

-- check if dropped

select * from londiste.find_table_fkeys('public.ref_1');
select * from londiste.find_table_fkeys('public.ref_2');
select * from londiste.find_table_fkeys('public.ref_3');

-- look state
select * from londiste.get_table_pending_fkeys('public.ref_2');
select * from londiste.get_valid_pending_fkeys('branch_set');

-- toggle sync
select * from londiste.local_set_table_state('branch_set', 'public.ref_1', null, 'ok');
select * from londiste.get_valid_pending_fkeys('branch_set');
select * from londiste.local_set_table_state('branch_set', 'public.ref_2', null, 'ok');
select * from londiste.get_valid_pending_fkeys('branch_set');
select * from londiste.local_set_table_state('branch_set', 'public.ref_3', null, 'ok');
select * from londiste.get_valid_pending_fkeys('branch_set');

-- restore: old
select * from londiste.get_table_pending_fkeys('public.ref_2');
select * from londiste.restore_table_fkey('public.ref_2', 'ref_2_ref_fkey');
select * from londiste.get_table_pending_fkeys('public.ref_2');

-- restore: new
select * from londiste.get_table_pending_fkeys('public.ref_3');

select londiste.restore_table_fkey('public.ref_3', 'ref_3_ref2_fkey', true) as step1;
\gset
:step1 ;

select londiste.restore_table_fkey('public.ref_3', 'ref_3_ref2_fkey', true) as step2;
\gset
:step2 ;

select londiste.restore_table_fkey('public.ref_3', 'ref_3_ref2_fkey', true) as step3;

select * from londiste.get_table_pending_fkeys('public.ref_3');

-- look state
select * from londiste.get_table_pending_fkeys('public.ref_2');
select * from londiste.get_valid_pending_fkeys('branch_set');
select * from londiste.find_table_fkeys('public.ref_1');
select * from londiste.find_table_fkeys('public.ref_2');
select * from londiste.find_table_fkeys('public.ref_3');