|
1 | | --- Target PostgreSQL database used by functional tests to validate a generated |
2 | | --- dump. The dump is supposed to be self-sufficient (CREATE SCHEMA + DDL + |
3 | | --- COPY/INSERT), so this init script only ensures the database exists and is |
4 | | --- otherwise empty. |
| 1 | +-- Functional-test fixture for PostgreSQL. |
| 2 | +-- |
| 3 | +-- The "db2sqltarget" database (created from POSTGRES_DB by the entrypoint) is |
| 4 | +-- used both as: |
| 5 | +-- * a TARGET database for dumps produced by db2sql (apply step) — left |
| 6 | +-- untouched outside the apptest schema below; |
| 7 | +-- * a SOURCE database whose ``apptest`` schema mirrors the mssql/oracle |
| 8 | +-- fixtures (type_matrix + author/book) so the PostgreSQL reader can be |
| 9 | +-- exercised by the functional suite. |
| 10 | +-- |
| 11 | +-- The reader filters out pg_catalog/information_schema/pg_toast, so the |
| 12 | +-- ``apptest`` schema is the only one surfaced by collect_metadata(). |
| 13 | +-- Note: types covered are the PG-native ones referenced by |
| 14 | +-- ``PostgresSqlEmitter.DEFAULT_TYPE_MAP`` (no MSSQL/Oracle-only types). |
5 | 15 |
|
6 | | --- The database "db2sqltarget" is created from POSTGRES_DB by the entrypoint, |
7 | | --- so nothing else is strictly required here. We keep the file so the volume |
8 | | --- mount /docker-entrypoint-initdb.d is non-empty and to host any future |
9 | | --- preconditioning (extensions, roles, etc.). |
| 16 | +CREATE SCHEMA IF NOT EXISTS apptest; |
10 | 17 |
|
11 | | -SELECT 'postgres target ready' AS status; |
| 18 | +DROP TABLE IF EXISTS apptest.book; |
| 19 | +DROP TABLE IF EXISTS apptest.author; |
| 20 | +DROP TABLE IF EXISTS apptest.type_matrix; |
| 21 | + |
| 22 | +-- Type-coverage table ------------------------------------------------------- |
| 23 | +CREATE TABLE apptest.type_matrix ( |
| 24 | + id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 25 | + c_boolean BOOLEAN, |
| 26 | + c_smallint SMALLINT, |
| 27 | + c_integer INTEGER, |
| 28 | + c_bigint BIGINT, |
| 29 | + c_real REAL, |
| 30 | + c_double DOUBLE PRECISION, |
| 31 | + c_numeric NUMERIC(18, 6), |
| 32 | + c_decimal DECIMAL(12, 4), |
| 33 | + c_char CHAR(8), |
| 34 | + c_varchar VARCHAR(64), |
| 35 | + c_text TEXT, |
| 36 | + c_bytea BYTEA, |
| 37 | + c_date DATE, |
| 38 | + c_time TIME, |
| 39 | + c_timestamp TIMESTAMP, |
| 40 | + c_timestamptz TIMESTAMP WITH TIME ZONE, |
| 41 | + c_uuid UUID, |
| 42 | + c_json JSON, |
| 43 | + c_jsonb JSONB, |
| 44 | + c_xml XML |
| 45 | +); |
| 46 | + |
| 47 | +-- Relational mini-fixture (parallels mssql/oracle/sqlite fixtures) |
| 48 | +CREATE TABLE apptest.author ( |
| 49 | + id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 50 | + name VARCHAR(120) NOT NULL, |
| 51 | + birth_year INTEGER |
| 52 | +); |
| 53 | + |
| 54 | +CREATE TABLE apptest.book ( |
| 55 | + id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 56 | + author_id INTEGER NOT NULL, |
| 57 | + title VARCHAR(200) NOT NULL, |
| 58 | + CONSTRAINT fk_book_author FOREIGN KEY (author_id) REFERENCES apptest.author (id) |
| 59 | +); |
| 60 | + |
| 61 | +CREATE INDEX idx_book_title ON apptest.book (title); |
| 62 | + |
| 63 | +-- Representative payload (one populated row + one all-NULL row) |
| 64 | +INSERT INTO apptest.type_matrix |
| 65 | + (c_boolean, c_smallint, c_integer, c_bigint, |
| 66 | + c_real, c_double, c_numeric, c_decimal, |
| 67 | + c_char, c_varchar, c_text, c_bytea, |
| 68 | + c_date, c_time, c_timestamp, c_timestamptz, |
| 69 | + c_uuid, c_json, c_jsonb, c_xml) |
| 70 | +VALUES |
| 71 | + (TRUE, 32100, 2147483640, 9000000000000000000, |
| 72 | + 1.5, 3.141592653589793, 1234567.890123, 1234.5678, |
| 73 | + 'fixed', 'with accent é', 'long text payload', '\xDEADBEEFCAFEBABE', |
| 74 | + DATE '2024-01-31', TIME '14:30:00', |
| 75 | + TIMESTAMP '2024-01-31 14:30:00', |
| 76 | + TIMESTAMP WITH TIME ZONE '2024-01-31 14:30:00+01', |
| 77 | + '11111111-2222-3333-4444-555555555555', |
| 78 | + '{"k": "v"}', '{"k": "v"}', |
| 79 | + XMLPARSE(DOCUMENT '<root><k>v</k></root>')), |
| 80 | + (NULL, NULL, NULL, NULL, |
| 81 | + NULL, NULL, NULL, NULL, |
| 82 | + NULL, NULL, NULL, NULL, |
| 83 | + NULL, NULL, NULL, NULL, |
| 84 | + NULL, NULL, NULL, NULL); |
| 85 | + |
| 86 | +INSERT INTO apptest.author (name, birth_year) VALUES ('Alice', 1980); |
| 87 | +INSERT INTO apptest.author (name, birth_year) VALUES ('Bob', NULL); |
| 88 | + |
| 89 | +INSERT INTO apptest.book (author_id, title) VALUES (1, 'First'); |
| 90 | +INSERT INTO apptest.book (author_id, title) VALUES (1, 'Second''s ride'); |
| 91 | +INSERT INTO apptest.book (author_id, title) VALUES (2, 'Bob book'); |
| 92 | + |
| 93 | +SELECT 'postgres apptest fixture loaded' AS status; |
0 commit comments