How I can update one database schema to another database?



  • I have 2 databases in the same postgresql server:

    • mybd: used for development
    • test_mydb: used for testing is is preseeded with some test data that are significantly smaller than mydb

    The mydb is updated via migration scripts. What I want is to sync the changes after the migrations are run into the test_mydb afterwards, I want to pg_dump the contents of test_mydb in order to generate a test dump.

    Is there a way to look for diferences between 2 schemas of the database mydb and test_mydb and apply them to test_mydb?

    I want schema-only differences and not full data replication.



  • You can use pg_dump to generate the DB object scripts, then compare the text files. Not sure whether pg_dump generate the objects in specific order. If yes, you can use a program like diff to do the comparison. Otherwise, you may need to compare manually.

    The following pg_dump options will be useful

      -n, --schema=PATTERN         dump the specified schema(s) only
      -s, --schema-only            dump only the schema, no data
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2