@tricoteuses/senat 3.1.19 → 3.1.21
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.
- package/LICENSE.md +32 -32
- package/README.md +326 -326
- package/lib/src/other_types/collaborateurs.d.ts +5 -0
- package/lib/src/other_types/manifest.d.ts +11 -0
- package/lib/src/parsers/collaborateurs.d.ts +44 -0
- package/lib/src/parsers/collaborateurs.js +157 -0
- package/lib/src/scripts/retrieve_agenda.js +38 -4
- package/lib/src/scripts/retrieve_collaborateurs.js +166 -0
- package/lib/src/scripts/retrieve_videos.js +5 -1
- package/lib/src/scripts/shared/incremental_import_sql.js +859 -859
- package/lib/src/scripts/shared/schema_version.js +84 -84
- package/lib/src/scripts/shared/staging_metadata_sql.js +214 -214
- package/lib/src/scripts/validate_prefixed_tables.js +12 -12
- package/lib/src/server/ameli.js +11 -11
- package/lib/src/server/conversion_textes.js +106 -106
- package/lib/src/server/debats.js +10 -10
- package/lib/src/server/documents.js +22 -22
- package/lib/src/server/dosleg.js +33 -33
- package/lib/src/server/questions.js +10 -10
- package/lib/src/server/scrutins.js +3 -3
- package/lib/src/server/sens.js +19 -19
- package/lib/src/utils/manifest.d.ts +6 -0
- package/lib/src/utils/manifest.js +37 -0
- package/lib/src/utils/reunion_deletion.d.ts +2 -0
- package/lib/src/utils/reunion_deletion.js +27 -0
- package/lib/src/videos/match.js +4 -4
- package/lib/tests/collaborateurs.test.js +115 -0
- package/package.json +117 -117
- package/lib/src/config.d.ts +0 -21
- package/lib/src/config.js +0 -27
- package/lib/src/conversion_textes.d.ts +0 -11
- package/lib/src/conversion_textes.js +0 -316
- package/lib/src/databases.d.ts +0 -2
- package/lib/src/databases.js +0 -26
- package/lib/src/datasets.d.ts +0 -34
- package/lib/src/datasets.js +0 -233
- package/lib/src/git.d.ts +0 -26
- package/lib/src/git.js +0 -217
- package/lib/src/loaders.d.ts +0 -52
- package/lib/src/loaders.js +0 -254
- package/lib/src/model/agenda.d.ts +0 -6
- package/lib/src/model/agenda.js +0 -148
- package/lib/src/model/ameli.d.ts +0 -55
- package/lib/src/model/ameli.js +0 -148
- package/lib/src/model/commission.d.ts +0 -18
- package/lib/src/model/commission.js +0 -269
- package/lib/src/model/debats.d.ts +0 -67
- package/lib/src/model/debats.js +0 -95
- package/lib/src/model/documents.d.ts +0 -12
- package/lib/src/model/documents.js +0 -141
- package/lib/src/model/dosleg.d.ts +0 -7
- package/lib/src/model/dosleg.js +0 -326
- package/lib/src/model/index.d.ts +0 -7
- package/lib/src/model/index.js +0 -7
- package/lib/src/model/questions.d.ts +0 -45
- package/lib/src/model/questions.js +0 -89
- package/lib/src/model/scrutins.d.ts +0 -13
- package/lib/src/model/scrutins.js +0 -114
- package/lib/src/model/seance.d.ts +0 -3
- package/lib/src/model/seance.js +0 -267
- package/lib/src/model/sens.d.ts +0 -182
- package/lib/src/model/sens.js +0 -485
- package/lib/src/model/util.d.ts +0 -9
- package/lib/src/model/util.js +0 -38
- package/lib/src/raw_types/ameli.d.ts +0 -914
- package/lib/src/raw_types/ameli.js +0 -5
- package/lib/src/raw_types/debats.d.ts +0 -207
- package/lib/src/raw_types/debats.js +0 -5
- package/lib/src/raw_types/dosleg.d.ts +0 -1619
- package/lib/src/raw_types/dosleg.js +0 -5
- package/lib/src/raw_types/questions.d.ts +0 -423
- package/lib/src/raw_types/questions.js +0 -5
- package/lib/src/raw_types/senat.d.ts +0 -11372
- package/lib/src/raw_types/senat.js +0 -5
- package/lib/src/raw_types/sens.d.ts +0 -8248
- package/lib/src/raw_types/sens.js +0 -5
- package/lib/src/raw_types_schemats/ameli.d.ts +0 -539
- package/lib/src/raw_types_schemats/ameli.js +0 -2
- package/lib/src/raw_types_schemats/debats.d.ts +0 -127
- package/lib/src/raw_types_schemats/debats.js +0 -2
- package/lib/src/raw_types_schemats/dosleg.d.ts +0 -977
- package/lib/src/raw_types_schemats/dosleg.js +0 -2
- package/lib/src/raw_types_schemats/questions.d.ts +0 -237
- package/lib/src/raw_types_schemats/questions.js +0 -2
- package/lib/src/raw_types_schemats/sens.d.ts +0 -6915
- package/lib/src/raw_types_schemats/sens.js +0 -2
- package/lib/src/scripts/test_iter_load.js +0 -12
- package/lib/src/types/agenda.d.ts +0 -45
- package/lib/src/types/ameli.d.ts +0 -5
- package/lib/src/types/compte_rendu.d.ts +0 -83
- package/lib/src/types/debats.d.ts +0 -2
- package/lib/src/types/debats.js +0 -1
- package/lib/src/types/dosleg.d.ts +0 -70
- package/lib/src/types/dosleg.js +0 -1
- package/lib/src/types/questions.d.ts +0 -2
- package/lib/src/types/questions.js +0 -1
- package/lib/src/types/sens.d.ts +0 -10
- package/lib/src/types/sens.js +0 -1
- package/lib/src/types/sessions.d.ts +0 -6
- package/lib/src/types/sessions.js +0 -19
- package/lib/src/types/texte.d.ts +0 -72
- package/lib/src/types/texte.js +0 -15
- package/lib/src/validators/config.d.ts +0 -9
- package/lib/src/validators/config.js +0 -10
- /package/lib/src/{scripts/test_iter_load.d.ts → other_types/collaborateurs.js} +0 -0
- /package/lib/src/{types/agenda.js → other_types/manifest.js} +0 -0
- /package/lib/src/{types/ameli.js → scripts/retrieve_collaborateurs.d.ts} +0 -0
- /package/lib/{src/types/compte_rendu.js → tests/collaborateurs.test.d.ts} +0 -0
|
@@ -2,94 +2,94 @@ function escapeSqlLiteral(value) {
|
|
|
2
2
|
return value.replace(/'/g, "''");
|
|
3
3
|
}
|
|
4
4
|
export function buildEnsureSchemaVersionTableSql(schemaName) {
|
|
5
|
-
return `
|
|
6
|
-
CREATE TABLE IF NOT EXISTS ${schemaName}.version(
|
|
7
|
-
number integer PRIMARY KEY
|
|
8
|
-
);
|
|
9
|
-
COMMENT ON TABLE ${schemaName}.version IS 'version of database';
|
|
10
|
-
COMMENT ON COLUMN ${schemaName}.version.number IS 'version number of database schema';
|
|
11
|
-
INSERT INTO ${schemaName}.version(number)
|
|
12
|
-
SELECT 0
|
|
13
|
-
WHERE NOT EXISTS (SELECT 1 FROM ${schemaName}.version);
|
|
5
|
+
return `
|
|
6
|
+
CREATE TABLE IF NOT EXISTS ${schemaName}.version(
|
|
7
|
+
number integer PRIMARY KEY
|
|
8
|
+
);
|
|
9
|
+
COMMENT ON TABLE ${schemaName}.version IS 'version of database';
|
|
10
|
+
COMMENT ON COLUMN ${schemaName}.version.number IS 'version number of database schema';
|
|
11
|
+
INSERT INTO ${schemaName}.version(number)
|
|
12
|
+
SELECT 0
|
|
13
|
+
WHERE NOT EXISTS (SELECT 1 FROM ${schemaName}.version);
|
|
14
14
|
`;
|
|
15
15
|
}
|
|
16
16
|
export function buildSchemaStructureFingerprintQuery(schemaName) {
|
|
17
17
|
const escapedSchemaName = escapeSqlLiteral(schemaName);
|
|
18
|
-
return `
|
|
19
|
-
WITH objects AS (
|
|
20
|
-
SELECT format('table:%s', table_class.relname) AS entry
|
|
21
|
-
FROM pg_class table_class
|
|
22
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
23
|
-
WHERE table_namespace.nspname = '${escapedSchemaName}'
|
|
24
|
-
AND table_class.relkind IN ('r', 'p')
|
|
25
|
-
AND table_class.relname <> 'version'
|
|
26
|
-
|
|
27
|
-
UNION ALL
|
|
28
|
-
|
|
29
|
-
SELECT format(
|
|
30
|
-
'column:%s:%s:%s:%s:%s:%s:%s:%s',
|
|
31
|
-
columns.table_name,
|
|
32
|
-
columns.ordinal_position,
|
|
33
|
-
columns.column_name,
|
|
34
|
-
columns.udt_schema,
|
|
35
|
-
columns.udt_name,
|
|
36
|
-
columns.is_nullable,
|
|
37
|
-
coalesce(columns.column_default, ''),
|
|
38
|
-
columns.is_identity
|
|
39
|
-
) AS entry
|
|
40
|
-
FROM information_schema.columns columns
|
|
41
|
-
WHERE columns.table_schema = '${escapedSchemaName}'
|
|
42
|
-
AND columns.table_name <> 'version'
|
|
43
|
-
|
|
44
|
-
UNION ALL
|
|
45
|
-
|
|
46
|
-
SELECT format(
|
|
47
|
-
'constraint:%s:%s:%s:%s',
|
|
48
|
-
table_class.relname,
|
|
49
|
-
constraint_data.contype,
|
|
50
|
-
constraint_data.conname,
|
|
51
|
-
pg_get_constraintdef(constraint_data.oid, true)
|
|
52
|
-
) AS entry
|
|
53
|
-
FROM pg_constraint constraint_data
|
|
54
|
-
JOIN pg_class table_class ON table_class.oid = constraint_data.conrelid
|
|
55
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
56
|
-
WHERE table_namespace.nspname = '${escapedSchemaName}'
|
|
57
|
-
AND table_class.relname <> 'version'
|
|
58
|
-
AND constraint_data.contype <> 'n'
|
|
59
|
-
|
|
60
|
-
UNION ALL
|
|
61
|
-
|
|
62
|
-
SELECT format(
|
|
63
|
-
'index:%s:%s',
|
|
64
|
-
table_class.relname,
|
|
65
|
-
pg_get_indexdef(idx.indexrelid)
|
|
66
|
-
) AS entry
|
|
67
|
-
FROM pg_index idx
|
|
68
|
-
JOIN pg_class table_class ON table_class.oid = idx.indrelid
|
|
69
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
70
|
-
LEFT JOIN pg_constraint constraint_data ON constraint_data.conindid = idx.indexrelid
|
|
71
|
-
WHERE table_namespace.nspname = '${escapedSchemaName}'
|
|
72
|
-
AND table_class.relname <> 'version'
|
|
73
|
-
AND constraint_data.oid IS NULL
|
|
74
|
-
|
|
75
|
-
UNION ALL
|
|
76
|
-
|
|
77
|
-
SELECT format(
|
|
78
|
-
'sequence:%s:%s:%s:%s:%s:%s:%s:%s',
|
|
79
|
-
sequences.sequencename,
|
|
80
|
-
sequences.data_type,
|
|
81
|
-
sequences.start_value,
|
|
82
|
-
sequences.min_value,
|
|
83
|
-
sequences.max_value,
|
|
84
|
-
sequences.increment_by,
|
|
85
|
-
sequences.cycle,
|
|
86
|
-
sequences.cache_size
|
|
87
|
-
) AS entry
|
|
88
|
-
FROM pg_sequences sequences
|
|
89
|
-
WHERE sequences.schemaname = '${escapedSchemaName}'
|
|
90
|
-
)
|
|
91
|
-
SELECT coalesce(md5(string_agg(entry, E'\\n' ORDER BY entry)), '')
|
|
92
|
-
FROM objects
|
|
18
|
+
return `
|
|
19
|
+
WITH objects AS (
|
|
20
|
+
SELECT format('table:%s', table_class.relname) AS entry
|
|
21
|
+
FROM pg_class table_class
|
|
22
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
23
|
+
WHERE table_namespace.nspname = '${escapedSchemaName}'
|
|
24
|
+
AND table_class.relkind IN ('r', 'p')
|
|
25
|
+
AND table_class.relname <> 'version'
|
|
26
|
+
|
|
27
|
+
UNION ALL
|
|
28
|
+
|
|
29
|
+
SELECT format(
|
|
30
|
+
'column:%s:%s:%s:%s:%s:%s:%s:%s',
|
|
31
|
+
columns.table_name,
|
|
32
|
+
columns.ordinal_position,
|
|
33
|
+
columns.column_name,
|
|
34
|
+
columns.udt_schema,
|
|
35
|
+
columns.udt_name,
|
|
36
|
+
columns.is_nullable,
|
|
37
|
+
coalesce(columns.column_default, ''),
|
|
38
|
+
columns.is_identity
|
|
39
|
+
) AS entry
|
|
40
|
+
FROM information_schema.columns columns
|
|
41
|
+
WHERE columns.table_schema = '${escapedSchemaName}'
|
|
42
|
+
AND columns.table_name <> 'version'
|
|
43
|
+
|
|
44
|
+
UNION ALL
|
|
45
|
+
|
|
46
|
+
SELECT format(
|
|
47
|
+
'constraint:%s:%s:%s:%s',
|
|
48
|
+
table_class.relname,
|
|
49
|
+
constraint_data.contype,
|
|
50
|
+
constraint_data.conname,
|
|
51
|
+
pg_get_constraintdef(constraint_data.oid, true)
|
|
52
|
+
) AS entry
|
|
53
|
+
FROM pg_constraint constraint_data
|
|
54
|
+
JOIN pg_class table_class ON table_class.oid = constraint_data.conrelid
|
|
55
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
56
|
+
WHERE table_namespace.nspname = '${escapedSchemaName}'
|
|
57
|
+
AND table_class.relname <> 'version'
|
|
58
|
+
AND constraint_data.contype <> 'n'
|
|
59
|
+
|
|
60
|
+
UNION ALL
|
|
61
|
+
|
|
62
|
+
SELECT format(
|
|
63
|
+
'index:%s:%s',
|
|
64
|
+
table_class.relname,
|
|
65
|
+
pg_get_indexdef(idx.indexrelid)
|
|
66
|
+
) AS entry
|
|
67
|
+
FROM pg_index idx
|
|
68
|
+
JOIN pg_class table_class ON table_class.oid = idx.indrelid
|
|
69
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
70
|
+
LEFT JOIN pg_constraint constraint_data ON constraint_data.conindid = idx.indexrelid
|
|
71
|
+
WHERE table_namespace.nspname = '${escapedSchemaName}'
|
|
72
|
+
AND table_class.relname <> 'version'
|
|
73
|
+
AND constraint_data.oid IS NULL
|
|
74
|
+
|
|
75
|
+
UNION ALL
|
|
76
|
+
|
|
77
|
+
SELECT format(
|
|
78
|
+
'sequence:%s:%s:%s:%s:%s:%s:%s:%s',
|
|
79
|
+
sequences.sequencename,
|
|
80
|
+
sequences.data_type,
|
|
81
|
+
sequences.start_value,
|
|
82
|
+
sequences.min_value,
|
|
83
|
+
sequences.max_value,
|
|
84
|
+
sequences.increment_by,
|
|
85
|
+
sequences.cycle,
|
|
86
|
+
sequences.cache_size
|
|
87
|
+
) AS entry
|
|
88
|
+
FROM pg_sequences sequences
|
|
89
|
+
WHERE sequences.schemaname = '${escapedSchemaName}'
|
|
90
|
+
)
|
|
91
|
+
SELECT coalesce(md5(string_agg(entry, E'\\n' ORDER BY entry)), '')
|
|
92
|
+
FROM objects
|
|
93
93
|
`;
|
|
94
94
|
}
|
|
95
95
|
export function buildIncrementSchemaVersionSql(schemaName) {
|
|
@@ -3,219 +3,219 @@ function escapeSqlLiteral(value) {
|
|
|
3
3
|
}
|
|
4
4
|
export function buildExportStagingMetadataStatementsQuery(stagingSchema, targetSchema) {
|
|
5
5
|
const escapedStagingSchema = escapeSqlLiteral(stagingSchema);
|
|
6
|
-
return `
|
|
7
|
-
WITH ordered_statements AS (
|
|
8
|
-
SELECT
|
|
9
|
-
10 AS group_no,
|
|
10
|
-
0 AS order_no,
|
|
11
|
-
sequences.sequencename AS object_name,
|
|
12
|
-
format('CREATE SEQUENCE IF NOT EXISTS %I.%I', '${targetSchema}', sequences.sequencename) AS statement
|
|
13
|
-
FROM pg_sequences sequences
|
|
14
|
-
WHERE sequences.schemaname = '${escapedStagingSchema}'
|
|
15
|
-
|
|
16
|
-
UNION ALL
|
|
17
|
-
|
|
18
|
-
SELECT
|
|
19
|
-
20 AS group_no,
|
|
20
|
-
0 AS order_no,
|
|
21
|
-
sequences.sequencename AS object_name,
|
|
22
|
-
format(
|
|
23
|
-
'ALTER SEQUENCE %I.%I AS %s INCREMENT BY %s MINVALUE %s MAXVALUE %s START WITH %s CACHE %s %s',
|
|
24
|
-
'${targetSchema}',
|
|
25
|
-
sequences.sequencename,
|
|
26
|
-
sequences.data_type,
|
|
27
|
-
sequences.increment_by,
|
|
28
|
-
sequences.min_value,
|
|
29
|
-
sequences.max_value,
|
|
30
|
-
sequences.start_value,
|
|
31
|
-
sequences.cache_size,
|
|
32
|
-
CASE WHEN sequences.cycle THEN 'CYCLE' ELSE 'NO CYCLE' END
|
|
33
|
-
) AS statement
|
|
34
|
-
FROM pg_sequences sequences
|
|
35
|
-
WHERE sequences.schemaname = '${escapedStagingSchema}'
|
|
36
|
-
|
|
37
|
-
UNION ALL
|
|
38
|
-
|
|
39
|
-
SELECT
|
|
40
|
-
30 AS group_no,
|
|
41
|
-
0 AS order_no,
|
|
42
|
-
sequence_class.relname AS object_name,
|
|
43
|
-
CASE
|
|
44
|
-
WHEN dependent_table.relname IS NULL THEN format(
|
|
45
|
-
'ALTER SEQUENCE %I.%I OWNED BY NONE',
|
|
46
|
-
'${targetSchema}',
|
|
47
|
-
sequence_class.relname
|
|
48
|
-
)
|
|
49
|
-
ELSE format(
|
|
50
|
-
'ALTER SEQUENCE %I.%I OWNED BY %I.%I.%I',
|
|
51
|
-
'${targetSchema}',
|
|
52
|
-
sequence_class.relname,
|
|
53
|
-
'${targetSchema}',
|
|
54
|
-
dependent_table.relname,
|
|
55
|
-
dependent_column.attname
|
|
56
|
-
)
|
|
57
|
-
END AS statement
|
|
58
|
-
FROM pg_class sequence_class
|
|
59
|
-
JOIN pg_namespace sequence_namespace ON sequence_namespace.oid = sequence_class.relnamespace
|
|
60
|
-
LEFT JOIN pg_depend dependency
|
|
61
|
-
ON dependency.objid = sequence_class.oid
|
|
62
|
-
AND dependency.deptype = 'a'
|
|
63
|
-
LEFT JOIN pg_class dependent_table ON dependent_table.oid = dependency.refobjid
|
|
64
|
-
LEFT JOIN pg_namespace dependent_namespace ON dependent_namespace.oid = dependent_table.relnamespace
|
|
65
|
-
LEFT JOIN pg_attribute dependent_column
|
|
66
|
-
ON dependent_column.attrelid = dependent_table.oid
|
|
67
|
-
AND dependent_column.attnum = dependency.refobjsubid
|
|
68
|
-
WHERE sequence_namespace.nspname = '${escapedStagingSchema}'
|
|
69
|
-
AND sequence_class.relkind = 'S'
|
|
70
|
-
AND (
|
|
71
|
-
dependent_namespace.nspname IS NULL
|
|
72
|
-
OR dependent_namespace.nspname = '${escapedStagingSchema}'
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
UNION ALL
|
|
76
|
-
|
|
77
|
-
SELECT
|
|
78
|
-
40 AS group_no,
|
|
79
|
-
0 AS order_no,
|
|
80
|
-
format('%s.%s', table_class.relname, attribute.attname) AS object_name,
|
|
81
|
-
CASE
|
|
82
|
-
WHEN default_expr.expression IS NULL THEN format(
|
|
83
|
-
'ALTER TABLE %I.%I ALTER COLUMN %I DROP DEFAULT',
|
|
84
|
-
'${targetSchema}',
|
|
85
|
-
table_class.relname,
|
|
86
|
-
attribute.attname
|
|
87
|
-
)
|
|
88
|
-
ELSE format(
|
|
89
|
-
'ALTER TABLE %I.%I ALTER COLUMN %I SET DEFAULT %s',
|
|
90
|
-
'${targetSchema}',
|
|
91
|
-
table_class.relname,
|
|
92
|
-
attribute.attname,
|
|
93
|
-
replace(default_expr.expression, '${stagingSchema}.', '${targetSchema}.')
|
|
94
|
-
)
|
|
95
|
-
END AS statement
|
|
96
|
-
FROM pg_class table_class
|
|
97
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
98
|
-
JOIN pg_attribute attribute ON attribute.attrelid = table_class.oid
|
|
99
|
-
LEFT JOIN LATERAL (
|
|
100
|
-
SELECT pg_get_expr(attr_def.adbin, attr_def.adrelid) AS expression
|
|
101
|
-
FROM pg_attrdef attr_def
|
|
102
|
-
WHERE attr_def.adrelid = attribute.attrelid
|
|
103
|
-
AND attr_def.adnum = attribute.attnum
|
|
104
|
-
) default_expr ON true
|
|
105
|
-
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
106
|
-
AND table_class.relkind IN ('r', 'p')
|
|
107
|
-
AND attribute.attnum > 0
|
|
108
|
-
AND NOT attribute.attisdropped
|
|
109
|
-
AND attribute.attgenerated = ''
|
|
110
|
-
AND attribute.attidentity = ''
|
|
111
|
-
|
|
112
|
-
UNION ALL
|
|
113
|
-
|
|
114
|
-
SELECT
|
|
115
|
-
50 AS group_no,
|
|
116
|
-
0 AS order_no,
|
|
117
|
-
table_class.relname AS object_name,
|
|
118
|
-
format(
|
|
119
|
-
'COMMENT ON TABLE %I.%I IS %L',
|
|
120
|
-
'${targetSchema}',
|
|
121
|
-
table_class.relname,
|
|
122
|
-
obj_description(table_class.oid, 'pg_class')
|
|
123
|
-
) AS statement
|
|
124
|
-
FROM pg_class table_class
|
|
125
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
126
|
-
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
127
|
-
AND table_class.relkind IN ('r', 'p')
|
|
128
|
-
|
|
129
|
-
UNION ALL
|
|
130
|
-
|
|
131
|
-
SELECT
|
|
132
|
-
60 AS group_no,
|
|
133
|
-
0 AS order_no,
|
|
134
|
-
format('%s.%s', table_class.relname, attribute.attname) AS object_name,
|
|
135
|
-
format(
|
|
136
|
-
'COMMENT ON COLUMN %I.%I.%I IS %L',
|
|
137
|
-
'${targetSchema}',
|
|
138
|
-
table_class.relname,
|
|
139
|
-
attribute.attname,
|
|
140
|
-
col_description(table_class.oid, attribute.attnum)
|
|
141
|
-
) AS statement
|
|
142
|
-
FROM pg_class table_class
|
|
143
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
144
|
-
JOIN pg_attribute attribute ON attribute.attrelid = table_class.oid
|
|
145
|
-
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
146
|
-
AND table_class.relkind IN ('r', 'p')
|
|
147
|
-
AND attribute.attnum > 0
|
|
148
|
-
AND NOT attribute.attisdropped
|
|
149
|
-
|
|
150
|
-
UNION ALL
|
|
151
|
-
|
|
152
|
-
SELECT
|
|
153
|
-
70 AS group_no,
|
|
154
|
-
CASE constraint_data.contype
|
|
155
|
-
WHEN 'p' THEN 1
|
|
156
|
-
WHEN 'u' THEN 2
|
|
157
|
-
WHEN 'c' THEN 3
|
|
158
|
-
WHEN 'f' THEN 4
|
|
159
|
-
ELSE 5
|
|
160
|
-
END AS order_no,
|
|
161
|
-
format('%s.%s', table_class.relname, constraint_data.conname) AS object_name,
|
|
162
|
-
format(
|
|
163
|
-
'ALTER TABLE %I.%I ADD CONSTRAINT %I %s',
|
|
164
|
-
'${targetSchema}',
|
|
165
|
-
table_class.relname,
|
|
166
|
-
constraint_data.conname,
|
|
167
|
-
replace(
|
|
168
|
-
replace(
|
|
169
|
-
pg_get_constraintdef(constraint_data.oid, true),
|
|
170
|
-
' REFERENCES ' || '${stagingSchema}' || '.',
|
|
171
|
-
' REFERENCES ${targetSchema}.'
|
|
172
|
-
),
|
|
173
|
-
' REFERENCES ONLY ' || '${stagingSchema}' || '.',
|
|
174
|
-
' REFERENCES ONLY ${targetSchema}.'
|
|
175
|
-
)
|
|
176
|
-
) AS statement
|
|
177
|
-
FROM pg_constraint constraint_data
|
|
178
|
-
JOIN pg_class table_class ON table_class.oid = constraint_data.conrelid
|
|
179
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
180
|
-
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
181
|
-
AND constraint_data.contype <> 'n'
|
|
182
|
-
|
|
183
|
-
UNION ALL
|
|
184
|
-
|
|
185
|
-
SELECT
|
|
186
|
-
80 AS group_no,
|
|
187
|
-
0 AS order_no,
|
|
188
|
-
format('%s.%s', table_class.relname, index_class.relname) AS object_name,
|
|
189
|
-
replace(
|
|
190
|
-
pg_get_indexdef(index_data.indexrelid),
|
|
191
|
-
' ON ${stagingSchema}.',
|
|
192
|
-
' ON ${targetSchema}.'
|
|
193
|
-
) AS statement
|
|
194
|
-
FROM pg_index index_data
|
|
195
|
-
JOIN pg_class table_class ON table_class.oid = index_data.indrelid
|
|
196
|
-
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
197
|
-
JOIN pg_class index_class ON index_class.oid = index_data.indexrelid
|
|
198
|
-
LEFT JOIN pg_constraint constraint_data ON constraint_data.conindid = index_data.indexrelid
|
|
199
|
-
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
200
|
-
AND constraint_data.oid IS NULL
|
|
201
|
-
|
|
202
|
-
UNION ALL
|
|
203
|
-
|
|
204
|
-
SELECT
|
|
205
|
-
90 AS group_no,
|
|
206
|
-
0 AS order_no,
|
|
207
|
-
sequences.sequencename AS object_name,
|
|
208
|
-
format(
|
|
209
|
-
'SELECT setval(%L, %s, %s)',
|
|
210
|
-
'${targetSchema}.' || sequences.sequencename,
|
|
211
|
-
coalesce(sequences.last_value, sequences.start_value),
|
|
212
|
-
CASE WHEN sequences.last_value IS NULL THEN 'false' ELSE 'true' END
|
|
213
|
-
) AS statement
|
|
214
|
-
FROM pg_sequences sequences
|
|
215
|
-
WHERE sequences.schemaname = '${escapedStagingSchema}'
|
|
216
|
-
)
|
|
217
|
-
SELECT encode(convert_to(statement, 'UTF8'), 'hex')
|
|
218
|
-
FROM ordered_statements
|
|
219
|
-
ORDER BY group_no, order_no, object_name;
|
|
6
|
+
return `
|
|
7
|
+
WITH ordered_statements AS (
|
|
8
|
+
SELECT
|
|
9
|
+
10 AS group_no,
|
|
10
|
+
0 AS order_no,
|
|
11
|
+
sequences.sequencename AS object_name,
|
|
12
|
+
format('CREATE SEQUENCE IF NOT EXISTS %I.%I', '${targetSchema}', sequences.sequencename) AS statement
|
|
13
|
+
FROM pg_sequences sequences
|
|
14
|
+
WHERE sequences.schemaname = '${escapedStagingSchema}'
|
|
15
|
+
|
|
16
|
+
UNION ALL
|
|
17
|
+
|
|
18
|
+
SELECT
|
|
19
|
+
20 AS group_no,
|
|
20
|
+
0 AS order_no,
|
|
21
|
+
sequences.sequencename AS object_name,
|
|
22
|
+
format(
|
|
23
|
+
'ALTER SEQUENCE %I.%I AS %s INCREMENT BY %s MINVALUE %s MAXVALUE %s START WITH %s CACHE %s %s',
|
|
24
|
+
'${targetSchema}',
|
|
25
|
+
sequences.sequencename,
|
|
26
|
+
sequences.data_type,
|
|
27
|
+
sequences.increment_by,
|
|
28
|
+
sequences.min_value,
|
|
29
|
+
sequences.max_value,
|
|
30
|
+
sequences.start_value,
|
|
31
|
+
sequences.cache_size,
|
|
32
|
+
CASE WHEN sequences.cycle THEN 'CYCLE' ELSE 'NO CYCLE' END
|
|
33
|
+
) AS statement
|
|
34
|
+
FROM pg_sequences sequences
|
|
35
|
+
WHERE sequences.schemaname = '${escapedStagingSchema}'
|
|
36
|
+
|
|
37
|
+
UNION ALL
|
|
38
|
+
|
|
39
|
+
SELECT
|
|
40
|
+
30 AS group_no,
|
|
41
|
+
0 AS order_no,
|
|
42
|
+
sequence_class.relname AS object_name,
|
|
43
|
+
CASE
|
|
44
|
+
WHEN dependent_table.relname IS NULL THEN format(
|
|
45
|
+
'ALTER SEQUENCE %I.%I OWNED BY NONE',
|
|
46
|
+
'${targetSchema}',
|
|
47
|
+
sequence_class.relname
|
|
48
|
+
)
|
|
49
|
+
ELSE format(
|
|
50
|
+
'ALTER SEQUENCE %I.%I OWNED BY %I.%I.%I',
|
|
51
|
+
'${targetSchema}',
|
|
52
|
+
sequence_class.relname,
|
|
53
|
+
'${targetSchema}',
|
|
54
|
+
dependent_table.relname,
|
|
55
|
+
dependent_column.attname
|
|
56
|
+
)
|
|
57
|
+
END AS statement
|
|
58
|
+
FROM pg_class sequence_class
|
|
59
|
+
JOIN pg_namespace sequence_namespace ON sequence_namespace.oid = sequence_class.relnamespace
|
|
60
|
+
LEFT JOIN pg_depend dependency
|
|
61
|
+
ON dependency.objid = sequence_class.oid
|
|
62
|
+
AND dependency.deptype = 'a'
|
|
63
|
+
LEFT JOIN pg_class dependent_table ON dependent_table.oid = dependency.refobjid
|
|
64
|
+
LEFT JOIN pg_namespace dependent_namespace ON dependent_namespace.oid = dependent_table.relnamespace
|
|
65
|
+
LEFT JOIN pg_attribute dependent_column
|
|
66
|
+
ON dependent_column.attrelid = dependent_table.oid
|
|
67
|
+
AND dependent_column.attnum = dependency.refobjsubid
|
|
68
|
+
WHERE sequence_namespace.nspname = '${escapedStagingSchema}'
|
|
69
|
+
AND sequence_class.relkind = 'S'
|
|
70
|
+
AND (
|
|
71
|
+
dependent_namespace.nspname IS NULL
|
|
72
|
+
OR dependent_namespace.nspname = '${escapedStagingSchema}'
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
UNION ALL
|
|
76
|
+
|
|
77
|
+
SELECT
|
|
78
|
+
40 AS group_no,
|
|
79
|
+
0 AS order_no,
|
|
80
|
+
format('%s.%s', table_class.relname, attribute.attname) AS object_name,
|
|
81
|
+
CASE
|
|
82
|
+
WHEN default_expr.expression IS NULL THEN format(
|
|
83
|
+
'ALTER TABLE %I.%I ALTER COLUMN %I DROP DEFAULT',
|
|
84
|
+
'${targetSchema}',
|
|
85
|
+
table_class.relname,
|
|
86
|
+
attribute.attname
|
|
87
|
+
)
|
|
88
|
+
ELSE format(
|
|
89
|
+
'ALTER TABLE %I.%I ALTER COLUMN %I SET DEFAULT %s',
|
|
90
|
+
'${targetSchema}',
|
|
91
|
+
table_class.relname,
|
|
92
|
+
attribute.attname,
|
|
93
|
+
replace(default_expr.expression, '${stagingSchema}.', '${targetSchema}.')
|
|
94
|
+
)
|
|
95
|
+
END AS statement
|
|
96
|
+
FROM pg_class table_class
|
|
97
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
98
|
+
JOIN pg_attribute attribute ON attribute.attrelid = table_class.oid
|
|
99
|
+
LEFT JOIN LATERAL (
|
|
100
|
+
SELECT pg_get_expr(attr_def.adbin, attr_def.adrelid) AS expression
|
|
101
|
+
FROM pg_attrdef attr_def
|
|
102
|
+
WHERE attr_def.adrelid = attribute.attrelid
|
|
103
|
+
AND attr_def.adnum = attribute.attnum
|
|
104
|
+
) default_expr ON true
|
|
105
|
+
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
106
|
+
AND table_class.relkind IN ('r', 'p')
|
|
107
|
+
AND attribute.attnum > 0
|
|
108
|
+
AND NOT attribute.attisdropped
|
|
109
|
+
AND attribute.attgenerated = ''
|
|
110
|
+
AND attribute.attidentity = ''
|
|
111
|
+
|
|
112
|
+
UNION ALL
|
|
113
|
+
|
|
114
|
+
SELECT
|
|
115
|
+
50 AS group_no,
|
|
116
|
+
0 AS order_no,
|
|
117
|
+
table_class.relname AS object_name,
|
|
118
|
+
format(
|
|
119
|
+
'COMMENT ON TABLE %I.%I IS %L',
|
|
120
|
+
'${targetSchema}',
|
|
121
|
+
table_class.relname,
|
|
122
|
+
obj_description(table_class.oid, 'pg_class')
|
|
123
|
+
) AS statement
|
|
124
|
+
FROM pg_class table_class
|
|
125
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
126
|
+
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
127
|
+
AND table_class.relkind IN ('r', 'p')
|
|
128
|
+
|
|
129
|
+
UNION ALL
|
|
130
|
+
|
|
131
|
+
SELECT
|
|
132
|
+
60 AS group_no,
|
|
133
|
+
0 AS order_no,
|
|
134
|
+
format('%s.%s', table_class.relname, attribute.attname) AS object_name,
|
|
135
|
+
format(
|
|
136
|
+
'COMMENT ON COLUMN %I.%I.%I IS %L',
|
|
137
|
+
'${targetSchema}',
|
|
138
|
+
table_class.relname,
|
|
139
|
+
attribute.attname,
|
|
140
|
+
col_description(table_class.oid, attribute.attnum)
|
|
141
|
+
) AS statement
|
|
142
|
+
FROM pg_class table_class
|
|
143
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
144
|
+
JOIN pg_attribute attribute ON attribute.attrelid = table_class.oid
|
|
145
|
+
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
146
|
+
AND table_class.relkind IN ('r', 'p')
|
|
147
|
+
AND attribute.attnum > 0
|
|
148
|
+
AND NOT attribute.attisdropped
|
|
149
|
+
|
|
150
|
+
UNION ALL
|
|
151
|
+
|
|
152
|
+
SELECT
|
|
153
|
+
70 AS group_no,
|
|
154
|
+
CASE constraint_data.contype
|
|
155
|
+
WHEN 'p' THEN 1
|
|
156
|
+
WHEN 'u' THEN 2
|
|
157
|
+
WHEN 'c' THEN 3
|
|
158
|
+
WHEN 'f' THEN 4
|
|
159
|
+
ELSE 5
|
|
160
|
+
END AS order_no,
|
|
161
|
+
format('%s.%s', table_class.relname, constraint_data.conname) AS object_name,
|
|
162
|
+
format(
|
|
163
|
+
'ALTER TABLE %I.%I ADD CONSTRAINT %I %s',
|
|
164
|
+
'${targetSchema}',
|
|
165
|
+
table_class.relname,
|
|
166
|
+
constraint_data.conname,
|
|
167
|
+
replace(
|
|
168
|
+
replace(
|
|
169
|
+
pg_get_constraintdef(constraint_data.oid, true),
|
|
170
|
+
' REFERENCES ' || '${stagingSchema}' || '.',
|
|
171
|
+
' REFERENCES ${targetSchema}.'
|
|
172
|
+
),
|
|
173
|
+
' REFERENCES ONLY ' || '${stagingSchema}' || '.',
|
|
174
|
+
' REFERENCES ONLY ${targetSchema}.'
|
|
175
|
+
)
|
|
176
|
+
) AS statement
|
|
177
|
+
FROM pg_constraint constraint_data
|
|
178
|
+
JOIN pg_class table_class ON table_class.oid = constraint_data.conrelid
|
|
179
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
180
|
+
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
181
|
+
AND constraint_data.contype <> 'n'
|
|
182
|
+
|
|
183
|
+
UNION ALL
|
|
184
|
+
|
|
185
|
+
SELECT
|
|
186
|
+
80 AS group_no,
|
|
187
|
+
0 AS order_no,
|
|
188
|
+
format('%s.%s', table_class.relname, index_class.relname) AS object_name,
|
|
189
|
+
replace(
|
|
190
|
+
pg_get_indexdef(index_data.indexrelid),
|
|
191
|
+
' ON ${stagingSchema}.',
|
|
192
|
+
' ON ${targetSchema}.'
|
|
193
|
+
) AS statement
|
|
194
|
+
FROM pg_index index_data
|
|
195
|
+
JOIN pg_class table_class ON table_class.oid = index_data.indrelid
|
|
196
|
+
JOIN pg_namespace table_namespace ON table_namespace.oid = table_class.relnamespace
|
|
197
|
+
JOIN pg_class index_class ON index_class.oid = index_data.indexrelid
|
|
198
|
+
LEFT JOIN pg_constraint constraint_data ON constraint_data.conindid = index_data.indexrelid
|
|
199
|
+
WHERE table_namespace.nspname = '${escapedStagingSchema}'
|
|
200
|
+
AND constraint_data.oid IS NULL
|
|
201
|
+
|
|
202
|
+
UNION ALL
|
|
203
|
+
|
|
204
|
+
SELECT
|
|
205
|
+
90 AS group_no,
|
|
206
|
+
0 AS order_no,
|
|
207
|
+
sequences.sequencename AS object_name,
|
|
208
|
+
format(
|
|
209
|
+
'SELECT setval(%L, %s, %s)',
|
|
210
|
+
'${targetSchema}.' || sequences.sequencename,
|
|
211
|
+
coalesce(sequences.last_value, sequences.start_value),
|
|
212
|
+
CASE WHEN sequences.last_value IS NULL THEN 'false' ELSE 'true' END
|
|
213
|
+
) AS statement
|
|
214
|
+
FROM pg_sequences sequences
|
|
215
|
+
WHERE sequences.schemaname = '${escapedStagingSchema}'
|
|
216
|
+
)
|
|
217
|
+
SELECT encode(convert_to(statement, 'UTF8'), 'hex')
|
|
218
|
+
FROM ordered_statements
|
|
219
|
+
ORDER BY group_no, order_no, object_name;
|
|
220
220
|
`;
|
|
221
221
|
}
|
|
@@ -9,12 +9,12 @@ const optionsDefinitions = [categoriesOption, silentOption];
|
|
|
9
9
|
const options = commandLineArgs(optionsDefinitions);
|
|
10
10
|
async function listPrefixedSenatTables(dataset) {
|
|
11
11
|
const prefix = `${dataset.database}_`;
|
|
12
|
-
const result = await sql `
|
|
13
|
-
select tablename
|
|
14
|
-
from pg_tables
|
|
15
|
-
where schemaname = ${senatSchemaName}
|
|
16
|
-
and tablename like ${prefix + "%"}
|
|
17
|
-
order by tablename
|
|
12
|
+
const result = await sql `
|
|
13
|
+
select tablename
|
|
14
|
+
from pg_tables
|
|
15
|
+
where schemaname = ${senatSchemaName}
|
|
16
|
+
and tablename like ${prefix + "%"}
|
|
17
|
+
order by tablename
|
|
18
18
|
`.execute(db);
|
|
19
19
|
return result.rows.map(({ tablename }) => tablename);
|
|
20
20
|
}
|
|
@@ -27,12 +27,12 @@ function listExpectedPrefixedSenatTables(dataset) {
|
|
|
27
27
|
return extractPrefixedTableNamesFromGeneratedManifest(manifest, dataset.database);
|
|
28
28
|
}
|
|
29
29
|
async function listColumns(schema, relationName) {
|
|
30
|
-
const result = await sql `
|
|
31
|
-
select column_name
|
|
32
|
-
from information_schema.columns
|
|
33
|
-
where table_schema = ${schema}
|
|
34
|
-
and table_name = ${relationName}
|
|
35
|
-
order by ordinal_position
|
|
30
|
+
const result = await sql `
|
|
31
|
+
select column_name
|
|
32
|
+
from information_schema.columns
|
|
33
|
+
where table_schema = ${schema}
|
|
34
|
+
and table_name = ${relationName}
|
|
35
|
+
order by ordinal_position
|
|
36
36
|
`.execute(db);
|
|
37
37
|
return result.rows.map(({ column_name }) => column_name);
|
|
38
38
|
}
|