From 21679753b8c6ff2e9982a447e0e6ee3b7812586f Mon Sep 17 00:00:00 2001 From: Valeh Date: Tue, 17 Nov 2026 14:06:30 +0400 Subject: [PATCH] chore: release 4.8.0 Bump version to 4.8.0 (control, META.json, pgclone.version()). Add sql/pgclone--4.8.0.sql and the no-op upgrade script 4.7.0--4.8.0. Changelog: conflict=ignore, partitioned tables, generated columns, table_async sequences, PG17+ SIGTERM fix. README roadmap: FK-aware sampling moves to 4.9.0. --- CHANGELOG.md | 14 +- META.json | 6 +- README.md | 3 +- pgclone.control | 2 +- sql/pgclone--4.7.0--4.8.0.sql | 10 + sql/pgclone--4.8.0.sql | 335 ++++++++++++++++++++++++++++++++++ src/pgclone.c | 2 +- 7 files changed, 363 insertions(+), 9 deletions(-) create mode 100644 sql/pgclone--4.7.0--4.8.0.sql create mode 100644 sql/pgclone--4.8.0.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index c753888..1aade30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,9 @@ All notable changes to pgclone are documented in this file. -## [Unreleased] +## [4.8.0] -### Docs -- README: add an "Upgrading" section — restart PostgreSQL after `make install` and before `ALTER EXTENSION pgclone UPDATE` (a stale preloaded library causes `could not find function ... in file pgclone.so`, issue #35). +This release has no SQL-level changes; after `make install`, **restart PostgreSQL**, then `ALTER EXTENSION pgclone UPDATE`. ### Added - `"conflict": "ignore"` (discussion #24): if the target table already exists, keep its definition (skip table DDL, constraints, indexes, triggers) and still load the data. Works in the sync and async paths. @@ -13,6 +12,15 @@ All notable changes to pgclone are documented in this file. ### Fixed - **Partitioned tables clone correctly (issue #38).** `pgclone.schema()`, `schema_async()` (including the parallel pool) and `table_async()` used to create a partitioned parent as a plain table and then abort with `cannot copy from partitioned table`. A partitioned parent is now created with `PARTITION BY`, each partition with `PARTITION OF FOR VALUES ...` (sub-partitioning included), and rows are copied once, from leaf partitions only. Partitions inherit the parent's primary key / indexes / triggers instead of having them cloned twice, and the table list is ordered so parents exist before their partitions (a pool worker waits for the parent). `pgclone.table()` on a partitioned parent creates just the parent; clone the schema (or each partition) to get the partitions. - **Generated columns stay generated, and COPY skips them.** `CREATE TABLE` reconstruction treated every `pg_attrdef` entry as a `DEFAULT`, so `GENERATED ALWAYS AS (...) STORED` columns (and PostgreSQL 18 `VIRTUAL` columns) were cloned as ordinary defaults. Once a column stays generated, a bare `COPY table` fails on the way in (`column "..." is a generated column`). Table DDL now emits `GENERATED ALWAYS AS (...) STORED` or `VIRTUAL`, and both the synchronous COPY path and the background worker omit generated columns so the target recomputes them. Ordinary defaults are unchanged. A generated column named in an explicit `"columns"` list is still rejected by the server; leave those columns out of the list. Virtual generated columns need PostgreSQL 18 on the target. +- **`table_async()` on tables with `serial` / `bigserial` columns (issue #33).** The single-table background path created the table without its sequence (`relation "..._id_seq" does not exist`). It now pre-creates the dependent sequences before `CREATE TABLE` and replays their current values after the copy, like `pgclone.table()`. +- **Background workers ignored SIGTERM on PostgreSQL 17+.** The worker's SIGTERM handler only sets `ShutdownRequestPending`, which `CHECK_FOR_INTERRUPTS()` does not service, so `pg_terminate_backend()` and server shutdown waited for the whole copy. Interrupt checks now also test that flag (`PGCLONE_CHECK_SHUTDOWN()`), and the COPY loop checks for interrupts, so a killed worker marks its job `failed` ("worker exited unexpectedly"). + +### Changed +- `test/test_chaos.sh` now actually exercises worker/coordinator termination: PIDs come from `pg_stat_activity`, workers are sent SIGTERM (SIGKILL crash-restarts the server), and the fixture is large enough to outlast the signal. Previously the tests passed without killing anything. +- New `test/test_partitions.sh` and async test 9 (`bigserial`); pgTAP plan 164 -> 168 (`conflict=ignore`) and group 32 (generated columns). + +### Docs +- README: add an "Upgrading" section — restart PostgreSQL after `make install` and before `ALTER EXTENSION pgclone UPDATE` (a stale preloaded library causes `could not find function ... in file pgclone.so`, issue #35). ## [4.7.0] diff --git a/META.json b/META.json index 70f808a..872de50 100644 --- a/META.json +++ b/META.json @@ -2,14 +2,14 @@ "name": "pgclone", "abstract": "Clone PostgreSQL databases, schemas, tables between staging, test, dev and prod environments", "description": "PostgreSQL extension for easily cloning your DB, Schemas, Tables and more between environments", - "version": "4.7.0", + "version": "4.8.0", "maintainer": "Valeh Agayev ", "license": "postgresql", "provides": { "pgclone": { "abstract": "Clone PostgreSQL databases, schemas, and tables across environments", - "file": "sql/pgclone--4.7.0.sql", - "version": "4.7.0" + "file": "sql/pgclone--4.8.0.sql", + "version": "4.8.0" } }, "prereqs": { diff --git a/README.md b/README.md index 3ac6597..eac5791 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,8 @@ pgclone uses Unix domain sockets for local loopback connections, so the default - [x] v4.5.0: Clone a table from Oracle into PostgreSQL — `pgclone.table_from_oracle()` with Oracle→PG type mapping, `dry_run`, CLOB/RAW support and an optional OCI build (`WITH_ORACLE=1`); verified in CI against Oracle Free - [x] v4.6.0: Clone a table from Microsoft SQL Server into PostgreSQL — `pgclone.table_from_sqlserver()` with SQL Server→PG type mapping, `dry_run`, `NVARCHAR(MAX)`/`VARBINARY`/`UNIQUEIDENTIFIER` support and an optional FreeTDS build (`WITH_SQLSERVER=1`); CI job against SQL Server 2022 - [x] v4.7.0: Clone a table from MySQL / MariaDB into PostgreSQL — `pgclone.table_from_mysql()` with MySQL→PG type mapping, `dry_run`, unsigned/`BIT`/`JSON`/`ENUM`/`SET`/`BLOB` support, zero-date handling and an optional client build (`WITH_MYSQL=1`); CI job against MySQL 8.0 -- [ ] v4.8.0: FK-aware referential sampling — sample N rows and follow foreign keys to keep child rows consistent (`pgclone.table_sample`) +- [x] v4.8.0: `"conflict": "ignore"`, partitioned-table cloning (`PARTITION BY` / `PARTITION OF`), generated columns, `table_async` sequences, PG17+ worker SIGTERM fix — see [CHANGELOG](CHANGELOG.md) +- [ ] v4.9.0: FK-aware referential sampling — sample N rows and follow foreign keys to keep child rows consistent (`pgclone.table_sample`) ## License diff --git a/pgclone.control b/pgclone.control index 0c1c8f3..5395d5d 100644 --- a/pgclone.control +++ b/pgclone.control @@ -1,6 +1,6 @@ # pgclone extension comment = 'Clone PostgreSQL databases, schemas, tables, roles and permissions with selective columns, data filtering, data masking/anonymization, async, parallel cloning, materialized views, resume, and conflict resolution, and Oracle-, SQL Server- and MySQL-to-PostgreSQL table cloning (optional OCI / FreeTDS / MySQL client builds)' -default_version = '4.7.0' +default_version = '4.8.0' module_pathname = '$libdir/pgclone' relocatable = false superuser = true diff --git a/sql/pgclone--4.7.0--4.8.0.sql b/sql/pgclone--4.7.0--4.8.0.sql new file mode 100644 index 0000000..54a62b4 --- /dev/null +++ b/sql/pgclone--4.7.0--4.8.0.sql @@ -0,0 +1,10 @@ +/* pgclone--4.7.0--4.8.0.sql */ +\echo Use "ALTER EXTENSION pgclone UPDATE" to load this file. \quit + +-- v4.8.0: no SQL-level changes. This release is C-level only: +-- * "conflict": "ignore" option +-- * partitioned tables cloned with PARTITION BY / PARTITION OF +-- * generated columns stay generated +-- * table_async creates and syncs sequences +-- * background workers honor SIGTERM on PG17+ +-- Restart PostgreSQL after installing the new library (shared_preload_libraries). diff --git a/sql/pgclone--4.8.0.sql b/sql/pgclone--4.8.0.sql new file mode 100644 index 0000000..33d0a4d --- /dev/null +++ b/sql/pgclone--4.8.0.sql @@ -0,0 +1,335 @@ +/* pgclone--4.8.0.sql */ +\echo Use "CREATE EXTENSION pgclone" to load this file. \quit + +-- v4.8.0: no SQL-level changes (conflict=ignore, partitioned tables, generated columns, +-- table_async sequences and the PG17+ SIGTERM fix are all C-level). +-- v4.7.0: pgclone.table_from_mysql() / pgclone.mysql_type_to_pg() (see bottom of file). +-- v4.6.0: pgclone.table_from_sqlserver() / pgclone.sqlserver_type_to_pg() (see bottom of file). +-- v4.5.0: pgclone.table_from_oracle() / pgclone.oracle_type_to_pg() — +-- clone a table from Oracle into PostgreSQL (see bottom of file). + +-- v4.4.4: Auto-discover bank account numbers; remote masking_report +-- (GitHub issue #23). +-- * discover_sensitive()/masking_report() now recognize bank account +-- / IBAN columns ("bank_account", "account_number", "acct_number", +-- "iban", etc.) and suggest the "null" strategy, the same +-- full-redaction treatment already used for SSN and credit card +-- numbers. C-only — no new SQL surface for this part. +-- * pgclone.masking_report() gains a 2-arg overload, +-- masking_report(source_conninfo, schema_name), so the +-- "sensitive but unmasked" audit the issue asked for can run +-- directly against a remote source — before anything is even +-- cloned — instead of requiring a local copy of the schema first +-- (declared below, alongside the original 1-arg version). + +-- v4.4.3: Conflict resolution ignored in the synchronous clone path +-- (GitHub issue #22). No new SQL surface — the existing "conflict" +-- key of the JSON options argument ("error"/"skip"/"replace"/ +-- "rename") used to be parsed only by the async bgworker path; +-- pgclone.table() and pgclone.schema() (and pgclone.database(), +-- which delegates to pgclone.schema()) accepted the option but +-- never acted on it, so an existing target just got a plain +-- "CREATE ... IF NOT EXISTS" no matter what strategy was requested +-- — reported as "replace" silently not replacing tables or +-- sequences. The fix is entirely in the C clone engine: "conflict" +-- is now parsed and honored by the synchronous path too, applied +-- to both tables and the sequences a schema clone creates directly, +-- and propagated from pgclone.schema()/pgclone.database() down to +-- each per-table / per-schema sub-call. Only acts when "conflict" +-- is explicitly set, so calls that never used the option keep the +-- exact previous behavior. + +-- v4.4.2: Constraint- and length-aware data masking (GitHub issue #18). +-- No new SQL surface — the fix is entirely in the C masking engine. +-- A mask is now skipped (with a WARNING) when applying it would break +-- the clone: text/constant/partial values that overflow a varchar(N) +-- column are clamped to fit; a "constant" that is not valid for a +-- numeric column, a "null" on a NOT NULL column, a value-collapsing +-- mask on a UNIQUE/PRIMARY KEY column (only "hash" is kept), and any +-- mask on a FOREIGN KEY column are all skipped. discover_sensitive() +-- and masking_report() only suggest strategies the engine will apply +-- (UNIQUE/PK and NOT NULL sensitive columns are steered to "hash"). + +-- v4.4.1: Type-aware data masking (GitHub issue #17). +-- No new SQL surface — the fix is entirely in the C masking engine. +-- A mask strategy whose output value the target column cannot store +-- (e.g. the numeric "random_int" strategy on a BOOLEAN column matched +-- by the %income% pattern) is now skipped with a WARNING instead of +-- aborting the clone with "invalid input syntax for type boolean". +-- pgclone.discover_sensitive() likewise no longer suggests a mask that +-- is incompatible with a column's type. + +-- v4.4.0: Schema/database-level in-line masking and table subset filters +-- No new SQL surface — both features are new keys in the existing JSON +-- options argument of pgclone.schema() / pgclone.database() / +-- pgclone.database_create(): +-- '{"tables": ["order_.*"], "exclude_tables": [".*_old"], +-- "masks": {"users": {"email": "email", "ssn": "null"}}}' + +-- v4.3.0: Consistent-snapshot clones (REPEATABLE READ READ ONLY) +-- No new SQL surface — the behaviour is enabled by default for every +-- table/schema/database clone (sync and async, including parallel +-- pool mode) and can be disabled per-call with the options JSON: +-- SELECT pgclone.schema('...', 'public', true, '{"consistent": false}'); +-- See CHANGELOG.md / docs/USAGE.md for details and tradeoffs. + +-- v4.0.0: All functions now live under the 'pgclone' schema. +-- Usage: SELECT pgclone.table(...), pgclone.schema(...), etc. +CREATE SCHEMA IF NOT EXISTS pgclone; + +-- SYNCHRONOUS +CREATE FUNCTION pgclone.table(source_conninfo TEXT, schema_name TEXT, table_name TEXT, include_data BOOLEAN DEFAULT true) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_table' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.table(source_conninfo TEXT, schema_name TEXT, table_name TEXT, include_data BOOLEAN, target_table_name TEXT) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_table' LANGUAGE C VOLATILE; +CREATE FUNCTION pgclone.table(source_conninfo TEXT, schema_name TEXT, table_name TEXT, include_data BOOLEAN, target_table_name TEXT, options TEXT) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_table' LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.table(TEXT, TEXT, TEXT, BOOLEAN, TEXT, TEXT) IS 'Clone table with JSON options: {"columns":["col1","col2"], "where":"status=''active''", "indexes":false, "constraints":false, "triggers":false, "mask":{"email":"email","name":"name","phone":"phone","col":{"type":"partial","prefix":2,"suffix":3},"col2":"hash","col3":"null","col4":{"type":"random_int","min":0,"max":100},"col5":{"type":"constant","value":"REDACTED"}}}'; +CREATE FUNCTION pgclone.table_ex(source_conninfo TEXT, schema_name TEXT, table_name TEXT, include_data BOOLEAN, target_table_name TEXT, include_indexes BOOLEAN DEFAULT true, include_constraints BOOLEAN DEFAULT true, include_triggers BOOLEAN DEFAULT true) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_table_ex' LANGUAGE C VOLATILE; +CREATE FUNCTION pgclone.schema(source_conninfo TEXT, schema_name TEXT, include_data BOOLEAN DEFAULT true) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_schema' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.schema(source_conninfo TEXT, schema_name TEXT, include_data BOOLEAN, options TEXT) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_schema' LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.schema(TEXT, TEXT, BOOLEAN, TEXT) IS 'Clone schema with JSON options: {"indexes":false, "constraints":false, "triggers":false, "tables":["regex1","regex2"], "exclude_tables":["regex"], "masks":{"table_name":{"col":"email"},"schema.table":{"col":"hash"}}} — tables/exclude_tables are anchored POSIX regexes selecting a subset of tables; masks applies per-table in-line masking during the COPY stream (v4.4.0).'; +CREATE FUNCTION pgclone.schema_ex(source_conninfo TEXT, schema_name TEXT, include_data BOOLEAN, include_indexes BOOLEAN DEFAULT true, include_constraints BOOLEAN DEFAULT true, include_triggers BOOLEAN DEFAULT true) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_schema_ex' LANGUAGE C VOLATILE; +CREATE FUNCTION pgclone.functions(source_conninfo TEXT, schema_name TEXT) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_functions' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.database(source_conninfo TEXT, include_data BOOLEAN DEFAULT true) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_database' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.database(source_conninfo TEXT, include_data BOOLEAN, options TEXT) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_database' LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.database(TEXT, BOOLEAN, TEXT) IS 'Clone database with JSON options — supports the same "tables", "exclude_tables", and "masks" options as pgclone.schema (v4.4.0); masks keys may be schema-qualified ("schema.table") to disambiguate.'; + +-- v2.0.1: Create target database and clone into it +CREATE FUNCTION pgclone.database_create(source_conninfo TEXT, target_dbname TEXT, include_data BOOLEAN DEFAULT true) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_database_create' LANGUAGE C VOLATILE; +CREATE FUNCTION pgclone.database_create(source_conninfo TEXT, target_dbname TEXT, include_data BOOLEAN, options TEXT) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_database_create' LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.database_create(TEXT, TEXT, BOOLEAN) IS 'Create target database if not exists, then clone all schemas/tables/functions from source. Run from postgres DB.'; + +-- ASYNC (require shared_preload_libraries = 'pgclone') +CREATE FUNCTION pgclone.table_async(source_conninfo TEXT, schema_name TEXT, table_name TEXT, include_data BOOLEAN DEFAULT true, target_table_name TEXT DEFAULT NULL, options TEXT DEFAULT NULL) RETURNS INTEGER AS 'MODULE_PATHNAME', 'pgclone_table_async' LANGUAGE C VOLATILE; +CREATE FUNCTION pgclone.schema_async(source_conninfo TEXT, schema_name TEXT, include_data BOOLEAN DEFAULT true, options TEXT DEFAULT NULL) RETURNS INTEGER AS 'MODULE_PATHNAME', 'pgclone_schema_async' LANGUAGE C VOLATILE; + +-- PROGRESS & JOB MANAGEMENT +CREATE FUNCTION pgclone.progress(job_id INTEGER) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_progress' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.cancel(job_id INTEGER) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_cancel' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.resume(job_id INTEGER) RETURNS INTEGER AS 'MODULE_PATHNAME', 'pgclone_resume' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.jobs() RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_jobs' LANGUAGE C VOLATILE STRICT; +CREATE FUNCTION pgclone.clear_jobs() RETURNS INTEGER AS 'MODULE_PATHNAME', 'pgclone_clear_jobs' LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.clear_jobs() IS 'Clear completed/failed/cancelled job slots from shared memory'; + +-- v2.1.0+v2.1.1+v2.1.2: Progress Tracking View with progress bar, elapsed time, ETA +CREATE FUNCTION pgclone.progress_detail() +RETURNS TABLE ( + job_id INTEGER, + status TEXT, + op_type TEXT, + schema_name TEXT, + table_name TEXT, + current_phase TEXT, + current_table TEXT, + tables_total BIGINT, + tables_completed BIGINT, + rows_copied BIGINT, + bytes_copied BIGINT, + elapsed_ms BIGINT, + start_time TIMESTAMPTZ, + end_time TIMESTAMPTZ, + error_message TEXT, + pct_complete DOUBLE PRECISION, + progress_bar TEXT, + elapsed_time TEXT +) AS 'MODULE_PATHNAME', 'pgclone_progress_view' +LANGUAGE C VOLATILE STRICT; + +COMMENT ON FUNCTION pgclone.progress_detail() IS 'Returns tabular progress with visual progress bar and elapsed time for all clone jobs'; + +-- VIEW: convenient wrapper +CREATE VIEW pgclone.jobs_view AS + SELECT * FROM pgclone.progress_detail(); + +COMMENT ON VIEW pgclone.jobs_view IS 'Live progress tracking view with progress bar and elapsed time for all pgclone async clone jobs'; + +-- v3.1.0: Auto-discovery of sensitive data +CREATE FUNCTION pgclone.discover_sensitive(source_conninfo TEXT, schema_name TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_discover_sensitive' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.discover_sensitive(TEXT, TEXT) IS 'Scan source schema for columns matching sensitive data patterns (email, name, phone, ssn, salary, etc.) and return suggested mask rules as JSON'; + +-- v3.2.0: Static data masking on local tables +CREATE FUNCTION pgclone.mask_in_place(schema_name TEXT, table_name TEXT, mask_json TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_mask_in_place' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.mask_in_place(TEXT, TEXT, TEXT) IS 'Apply data masking to an existing local table via UPDATE. mask_json uses same format as clone mask option: {"email": "email", "name": "name", "ssn": "null"}'; + +-- v3.3.0: Dynamic data masking via views and role-based access +CREATE FUNCTION pgclone.create_masking_policy(schema_name TEXT, table_name TEXT, mask_json TEXT, privileged_role TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_create_masking_policy' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.create_masking_policy(TEXT, TEXT, TEXT, TEXT) IS 'Create a dynamic masking policy: creates a masked view, revokes base table access from PUBLIC, grants view to PUBLIC, grants base table to privileged role'; + +CREATE FUNCTION pgclone.drop_masking_policy(schema_name TEXT, table_name TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_drop_masking_policy' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.drop_masking_policy(TEXT, TEXT) IS 'Remove a dynamic masking policy: drops the masked view and restores base table access to PUBLIC'; + +-- v3.4.0: Clone roles with permissions and passwords +CREATE FUNCTION pgclone.clone_roles(source_conninfo TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_clone_roles' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.clone_roles(TEXT) IS 'Clone all non-system roles from source with encrypted passwords, attributes, memberships, and all permissions. Requires superuser on both source and target.'; + +CREATE FUNCTION pgclone.clone_roles(source_conninfo TEXT, role_names TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_clone_roles' +LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.clone_roles(TEXT, TEXT) IS 'Clone specific roles (comma-separated) from source with encrypted passwords, attributes, memberships, and permissions. If role exists on target, syncs password and attributes without dropping.'; + +-- v3.5.0: Clone verification — compare row counts +CREATE FUNCTION pgclone.verify(source_conninfo TEXT, schema_name TEXT) +RETURNS TABLE ( + schema_name TEXT, + table_name TEXT, + source_rows BIGINT, + target_rows BIGINT, + match TEXT +) AS 'MODULE_PATHNAME', 'pgclone_verify' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.verify(TEXT, TEXT) IS 'Compare row counts between source and local target for all tables in a schema. Returns side-by-side comparison with match status.'; + +CREATE FUNCTION pgclone.verify(source_conninfo TEXT) +RETURNS TABLE ( + schema_name TEXT, + table_name TEXT, + source_rows BIGINT, + target_rows BIGINT, + match TEXT +) AS 'MODULE_PATHNAME', 'pgclone_verify' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.verify(TEXT) IS 'Compare row counts between source and local target for all user tables across all schemas. Returns side-by-side comparison with match status.'; + +-- v3.6.0: GDPR/Compliance masking report +CREATE FUNCTION pgclone.masking_report(schema_name TEXT) +RETURNS TABLE ( + schema_name TEXT, + table_name TEXT, + column_name TEXT, + sensitivity TEXT, + mask_status TEXT, + recommendation TEXT +) AS 'MODULE_PATHNAME', 'pgclone_masking_report' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.masking_report(TEXT) IS 'Generate GDPR/compliance audit report: lists sensitive columns, their masking status, and recommendations. Checks for masked views.'; + +-- v4.4.4: 2-arg overload — audit a remote source schema directly (issue #23) +CREATE FUNCTION pgclone.masking_report(source_conninfo TEXT, schema_name TEXT) +RETURNS TABLE ( + schema_name TEXT, + table_name TEXT, + column_name TEXT, + sensitivity TEXT, + mask_status TEXT, + recommendation TEXT +) AS 'MODULE_PATHNAME', 'pgclone_masking_report' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.masking_report(TEXT, TEXT) IS 'Generate GDPR/compliance audit report directly against a remote source schema (same output as masking_report(schema_name), run before anything is cloned locally).'; + +-- v4.1.0: Schema diff — DDL drift detection between source and local target +CREATE FUNCTION pgclone.diff(source_conninfo TEXT, schema_name TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_diff' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.diff(TEXT, TEXT) IS + 'Compare DDL of a schema between source and the local target. ' + 'Returns JSON drift report listing objects only_in_source / only_in_target / modified ' + 'across tables (with per-column type/nullability/default drift), indexes, ' + 'constraints, triggers, views, and sequences. Read-only on both sides.'; + +-- v4.2.0: Pre-flight validator — connection, permissions, version, capacity, +-- name-conflict, role and tablespace checks before a clone. +CREATE FUNCTION pgclone.preflight(source_conninfo TEXT, schema_name TEXT) +RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_preflight' +LANGUAGE C VOLATILE STRICT; +COMMENT ON FUNCTION pgclone.preflight(TEXT, TEXT) IS + 'Validate that a clone of the given schema from source into the local ' + 'target is likely to succeed. Returns JSON with errors / warnings / info ' + 'arrays plus a per-check breakdown covering: source/target connection, ' + 'PostgreSQL versions, schema existence, USAGE/SELECT/CREATE permissions, ' + 'estimated source size, target database size, object counts, name ' + 'conflicts on the target schema, missing extensions, missing roles, and ' + 'missing non-default tablespaces. Read-only on both sides.'; + +-- VERSION +CREATE FUNCTION pgclone.version() RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_version' LANGUAGE C IMMUTABLE STRICT; + +-- Oracle -> PostgreSQL table clone (requires a build with WITH_ORACLE=1). +CREATE FUNCTION pgclone.table_from_oracle( + oracle_conninfo TEXT, + oracle_schema TEXT, + oracle_table TEXT, + include_data BOOLEAN DEFAULT true, + target_schema TEXT DEFAULT 'public', + target_table TEXT DEFAULT NULL, + dry_run BOOLEAN DEFAULT false +) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_table_from_oracle' +LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.table_from_oracle(TEXT, TEXT, TEXT, BOOLEAN, TEXT, TEXT, BOOLEAN) IS 'Clone a table (structure, NOT NULL, PRIMARY KEY/UNIQUE, optionally data) from an Oracle database into PostgreSQL. oracle_conninfo: ''host=H port=1521 service=SVC user=U password=P'' or ''dsn=TNS_ALIAS user=U password=P''. dry_run returns the generated DDL without creating anything.'; + +-- Pure type-mapping helper (works without an Oracle client). For TIMESTAMP +-- types pass the fractional-seconds precision as data_scale. +CREATE FUNCTION pgclone.oracle_type_to_pg( + data_type TEXT, + data_length INTEGER DEFAULT NULL, + data_precision INTEGER DEFAULT NULL, + data_scale INTEGER DEFAULT NULL, + char_length INTEGER DEFAULT NULL +) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_oracle_type_to_pg' +LANGUAGE C IMMUTABLE; +COMMENT ON FUNCTION pgclone.oracle_type_to_pg(TEXT, INTEGER, INTEGER, INTEGER, INTEGER) IS 'Map an Oracle column type (as in ALL_TAB_COLUMNS) to the PostgreSQL type table_from_oracle() would create; NULL if unsupported.'; + +-- v4.6.0: clone a table from Microsoft SQL Server into PostgreSQL. + +-- SQL Server -> PostgreSQL table clone (requires a build with WITH_SQLSERVER=1). +CREATE FUNCTION pgclone.table_from_sqlserver( + sqlserver_conninfo TEXT, + sqlserver_schema TEXT, + sqlserver_table TEXT, + include_data BOOLEAN DEFAULT true, + target_schema TEXT DEFAULT 'public', + target_table TEXT DEFAULT NULL, + dry_run BOOLEAN DEFAULT false +) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_table_from_sqlserver' +LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.table_from_sqlserver(TEXT, TEXT, TEXT, BOOLEAN, TEXT, TEXT, BOOLEAN) IS 'Clone a table or view (structure, NOT NULL, PRIMARY KEY/UNIQUE, optionally data) from a Microsoft SQL Server database into PostgreSQL. sqlserver_conninfo: ''host=H port=1433 database=DB user=U password=P''. dry_run returns the generated DDL without creating anything.'; + +-- Pure type-mapping helper (works without a SQL Server client). max_length is +-- in bytes as in sys.columns (-1 = MAX). For time/datetime2/datetimeoffset +-- pass the fractional-seconds precision as "scale". +CREATE FUNCTION pgclone.sqlserver_type_to_pg( + data_type TEXT, + max_length INTEGER DEFAULT NULL, + "precision" INTEGER DEFAULT NULL, + scale INTEGER DEFAULT NULL +) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_sqlserver_type_to_pg' +LANGUAGE C IMMUTABLE; +COMMENT ON FUNCTION pgclone.sqlserver_type_to_pg(TEXT, INTEGER, INTEGER, INTEGER) IS 'Map a SQL Server column type (as in sys.columns) to the PostgreSQL type table_from_sqlserver() would create; NULL if unsupported.'; + +-- v4.7.0: clone a table from MySQL / MariaDB into PostgreSQL. + +-- MySQL -> PostgreSQL table clone (requires a build with WITH_MYSQL=1). +CREATE FUNCTION pgclone.table_from_mysql( + mysql_conninfo TEXT, + mysql_database TEXT, + mysql_table TEXT, + include_data BOOLEAN DEFAULT true, + target_schema TEXT DEFAULT 'public', + target_table TEXT DEFAULT NULL, + dry_run BOOLEAN DEFAULT false +) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_table_from_mysql' +LANGUAGE C VOLATILE; +COMMENT ON FUNCTION pgclone.table_from_mysql(TEXT, TEXT, TEXT, BOOLEAN, TEXT, TEXT, BOOLEAN) IS 'Clone a table or view (structure, NOT NULL, PRIMARY KEY/UNIQUE, optionally data) from a MySQL or MariaDB database into PostgreSQL. mysql_conninfo: ''host=H port=3306 user=U password=P''; mysql_database is the MySQL database (schema) holding the table. dry_run returns the generated DDL without creating anything.'; + +-- Pure type-mapping helper (works without a MySQL client). The arguments are +-- the information_schema.columns columns of the same names; column_type is only +-- used to detect "unsigned". For BIT pass the width as numeric_precision; for +-- TIME/DATETIME/TIMESTAMP pass the fractional-seconds precision as +-- datetime_precision. +CREATE FUNCTION pgclone.mysql_type_to_pg( + data_type TEXT, + column_type TEXT DEFAULT NULL, + char_length INTEGER DEFAULT NULL, + numeric_precision INTEGER DEFAULT NULL, + numeric_scale INTEGER DEFAULT NULL, + datetime_precision INTEGER DEFAULT NULL +) RETURNS TEXT AS 'MODULE_PATHNAME', 'pgclone_mysql_type_to_pg' +LANGUAGE C IMMUTABLE; +COMMENT ON FUNCTION pgclone.mysql_type_to_pg(TEXT, TEXT, INTEGER, INTEGER, INTEGER, INTEGER) IS 'Map a MySQL/MariaDB column type (as in information_schema.columns) to the PostgreSQL type table_from_mysql() would create; NULL if unsupported.'; diff --git a/src/pgclone.c b/src/pgclone.c index 436ccbf..432a618 100644 --- a/src/pgclone.c +++ b/src/pgclone.c @@ -5664,7 +5664,7 @@ PG_FUNCTION_INFO_V1(pgclone_version); Datum pgclone_version(PG_FUNCTION_ARGS) { - PG_RETURN_TEXT_P(cstring_to_text("pgclone 4.7.0")); + PG_RETURN_TEXT_P(cstring_to_text("pgclone 4.8.0")); } /* ===============================================================