Skip to content

Commit 54e5919

Browse files
committed
Add a boolean "migrate" flag for indexes
This allows to select which indexes should be migrated. That requires the creation of an otherwise redundant "indexes" table in the PostgreSQL staging schema. This closes #22.
1 parent ba7c8d1 commit 54e5919

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ Migration functions
372372
system schemas are processed.
373373
The names must be as they appear in Oracle, which is usually in upper case.
374374

375+
Indexes are only migrated if the `migrate` flag on the corresponding entries
376+
in the `tables` and `indexes` table in the PostgreSQL staging schema are set.
377+
375378
The return value is the number of captured errors that have been turned
376379
into warnings.
377380

TODO

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ List of things to do
33

44
- Support GENERATED AS IDENTITY with later Oracle versions.
55

6-
- Create a table "indexes" with a "migrate" column in the PostgreSQL stage
7-
to allow excluding certain indexes from the migration.
8-
See issue #22.
9-
106
- Refactor the code to create an abstraction layer that allows migration
117
from other databases using other foreign data wrappers.
128
This is a hard one.

ora_migrator--0.9.1.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,17 @@ BEGIN
925925
staging_schema)
926926
USING only_schemas;
927927

928+
/* refresh "indexes" table */
929+
INSERT INTO indexes (schema, table_name, index_name, uniqueness)
930+
SELECT DISTINCT schema,
931+
table_name,
932+
index_name,
933+
uniqueness
934+
FROM index_columns
935+
ON CONFLICT ON CONSTRAINT indexes_pkey DO UPDATE SET
936+
table_name = EXCLUDED.table_name,
937+
uniqueness = EXCLUDED.uniqueness;
938+
928939
/* copy "schemas" table */
929940
EXECUTE format(E'INSERT INTO schemas (schema)\n'
930941
' SELECT oracle_tolower(schema)\n'
@@ -1207,6 +1218,16 @@ BEGIN
12071218
PRIMARY KEY (schema, index_name, position)
12081219
);
12091220

1221+
CREATE TABLE indexes (
1222+
schema name NOT NULL,
1223+
table_name name NOT NULL,
1224+
index_name name NOT NULL,
1225+
uniqueness boolean NOT NULL,
1226+
migrate boolean NOT NULL DEFAULT TRUE,
1227+
CONSTRAINT indexes_pkey
1228+
PRIMARY KEY (schema, index_name)
1229+
);
1230+
12101231
CREATE TABLE schemas (
12111232
schema name NOT NULL
12121233
CONSTRAINT schemas_pkey PRIMARY KEY
@@ -2261,11 +2282,14 @@ BEGIN
22612282
FOR loc_s, loc_t, ind_name, uniq, colpos, des, is_expr, expr IN
22622283
SELECT schema, table_name, i.index_name, i.uniqueness, i.position, i.descend, i.is_expression, i.column_name
22632284
FROM index_columns i
2285+
JOIN indexes ind
2286+
USING (schema, table_name, index_name)
22642287
JOIN tables t
22652288
USING (schema, table_name)
22662289
WHERE (only_schemas IS NULL
22672290
OR schema =ANY (only_schemas))
22682291
AND t.migrate
2292+
AND ind.migrate
22692293
ORDER BY schema, table_name, i.index_name, i.position
22702294
LOOP
22712295
IF old_s <> loc_s OR old_t <> loc_t OR old_c <> ind_name THEN

0 commit comments

Comments
 (0)