Git Product home page Git Product logo

xinzf / pg-clone-schema Goto Github PK

View Code? Open in Web Editor NEW

This project forked from denishpatel/pg-clone-schema

0.0 0.0 0.0 885 KB

Postgres clone schema utility without need of going outside of database. Makes developers life easy by running single function to clone schema with all objects. It is very handy on Postgres RDS. Utility is sponsored by http://elephas.io/

License: MIT License

PLpgSQL 100.00%

pg-clone-schema's Introduction

clone_schema

Works on Linux distros and all Windows versions.

Handles following objects:

  • Tables - structure (indexes, constraints, keys) and optionally, data
  • Views, Materialized Views - Structure and data
  • Sequences, Serial, Identity
  • Functions/Procedures
  • Types (composite and enum)
  • Collations, Domains, Rules, Policies
  • Triggers, Trigger Functions
  • Comments
  • ACLs (Permissions/Grants)

Arguments:

  • source schema
  • target schema
  • clone with data (boolean)
  • only generate DDL (boolean)

You can call function like this to copy schema with data:

select clone_schema('sample', 'sample_clone', true, false);


Alternatively, if you want to copy only schema without data:

select clone_schema('sample', 'sample_clone', false, false);


If you just want to generate the DDL, call it like this:

select clone_schema('sample', 'sample_clone', false, true);

In this case, standard output with "INFO" lines are the generated DDL.


The schema_object_counts.sql file is useful for validating the cloning results. Just run it against source and target schemas to validate object counts after changing default schema name, sample.

Regression Testing Overview

Regression Testing is done in the following order:

  • Execute the sampledb.sql script to create the clone_testing database and the sample schema within it as the basis for the source schema.
  • Clone the sample schema in the 3 ways possible (save ddl only, create ddl only, or create ddl and copy rows).
  • Run the schema_object_counts.sql queries to compare object counts and rows from the source and target schemas.
  • Repeat all of the above for all supported versions of PG.

Limitations

  • Only works for PG Versions 10 and up.
  • You should not clone the "public" schema. The resulting output may not be accurate even if it finishes without any errors.
  • Foreign Tables are not handled at the present time. They must be done manually.
  • Functions/procedures that reference schema-qualified objects will not clone successfully. The target schema will still reference the source schema in these cases. To use this utility at the present time, you may need to remove schema-qualified references within your functions.


Sponsor: http://elephas.io/

Compare cloning with EnterpriseDB's version that only works with their Advanced Server: https://www.enterprisedb.com/edb-docs/d/edb-postgres-advanced-server/user-guides/user-guide/11/EDB_Postgres_Advanced_Server_Guide.1.078.html

pg-clone-schema's People

Contributors

michaeldba avatar denishpatel avatar guignonv avatar fsateler avatar espadav8 avatar leshik avatar gmonfardini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.