{"id":19223718,"url":"https://github.com/wmfs/pg-diff-sync","last_synced_at":"2025-04-20T23:31:42.908Z","repository":{"id":33110832,"uuid":"136919467","full_name":"wmfs/pg-diff-sync","owner":"wmfs","description":"Takes two objects that describe the structure of a database and produces the PostgreSQL statements required to get from one to the other.","archived":false,"fork":false,"pushed_at":"2025-02-16T00:21:33.000Z","size":398,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-15T18:49:57.043Z","etag":null,"topics":["package","postgresql","tymly"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wmfs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-11T11:53:57.000Z","updated_at":"2025-02-16T00:21:36.000Z","dependencies_parsed_at":"2024-01-05T20:38:13.041Z","dependency_job_id":"0bfb49ee-ded3-492f-af50-32325d781ffe","html_url":"https://github.com/wmfs/pg-diff-sync","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-diff-sync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-diff-sync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-diff-sync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmfs%2Fpg-diff-sync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wmfs","download_url":"https://codeload.github.com/wmfs/pg-diff-sync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249977433,"owners_count":21354859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["package","postgresql","tymly"],"created_at":"2024-11-09T15:09:21.720Z","updated_at":"2025-04-20T23:31:42.645Z","avatar_url":"https://github.com/wmfs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg-diff-sync\n[![Tymly Package](https://img.shields.io/badge/tymly-package-blue.svg)](https://tymly.io/)\n[![npm (scoped)](https://img.shields.io/npm/v/@wmfs/pg-diff-sync.svg)](https://www.npmjs.com/package/@wmfs/pg-diff-sync)\n[[![CircleCI](https://circleci.com/gh/wmfs/pg-diff-sync.svg?style=svg)](https://circleci.com/gh/wmfs/pg-diff-sync)\n[![codecov](https://codecov.io/gh/wmfs/pg-diff-sync/branch/master/graph/badge.svg)](https://codecov.io/gh/wmfs/pg-diff-sync)\n[![CodeFactor](https://www.codefactor.io/repository/github/wmfs/pg-diff-sync/badge)](https://www.codefactor.io/repository/github/wmfs/pg-diff-sync)\n[![Dependabot badge](https://img.shields.io/badge/Dependabot-active-brightgreen.svg)](https://dependabot.com/)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/wmfs/tymly/blob/master/packages/pg-concat/LICENSE)\n\n\n\n\t\n\u003e Takes two objects that describe the structure of a database and produces the PostgreSQL statements required to get from one to the other.\n\n## \u003ca name=\"install\"\u003e\u003c/a\u003eInstall\n```bash\n$ npm install pg-diff-sync --save\n```\n\n## \u003ca name=\"usage\"\u003e\u003c/a\u003eUsage\n\n```javascript\n  const pgDiffSync = require('pg-diff-sync')\n  const currentDbStructure = {...} \n  const expectedDbStructure = {...} \n\n  const statements = pgDiffSync(\n    currentDbStructure,\n    expectedDbStructure\n  )  \n  // Returns an array of DDL statements to apply on the PostgreSQL database\n```\n\n## \u003ca name=\"api\"\u003e\u003c/a\u003eAPI\n\n### pgDiffSync(baseDbStructure, targetDbStructure)\n\n### Arguments:\n| Arg  | Type | Notes |\n| ---  | ----- | ------ |\n| `baseDbStructure`  | `object`  | An object representing the original starting position of a database - most likely the output conjured from the __[pg-info](https://github.com/wmfs/pg-info)__ package |\n| `targetDbStructure`  | `object`  | And an object representing how the database needs to be - in the same form as `baseDbStructure` (again see the __[pg-info](https://github.com/wmfs/pg-info)__ package for more details) |\n\n## \u003ca name=\"output\"\u003e\u003c/a\u003eOutput\n\nThe output from __pg-diff-sync__ is a simple array of strings.\n\n* Each string is a separate DDL statement, that should be run on the PostgreSQL database that produced the `baseDbStructure` object. \n* With some caveats, running these statements on the _base_ database will turn it into the _target_ database\n\n__Example output__\n\n```json\n[\n  \"CREATE SCHEMA pg_diff_sync_test;\",\n  \"COMMENT ON SCHEMA pg_diff_sync_test IS 'Schema auto-generated by Relationize.js!';\",\n  \"CREATE TABLE pg_diff_sync_test.people();\",\n  \"COMMENT ON TABLE pg_diff_sync_test.people IS 'Just a simple list of people!';\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN employee_no text NOT NULL;\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN first_name text NOT NULL;\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN last_name text NOT NULL;\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN age integer;\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN _created timestamp with time zone NOT NULL DEFAULT now();\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN _created_by text;\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN _modified timestamp with time zone NOT NULL DEFAULT now();\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD COLUMN _modified_by text;\",\n  \"COMMENT ON COLUMN pg_diff_sync_test.people.first_name IS 'Person''s first name';\",\n  \"COMMENT ON COLUMN pg_diff_sync_test.people.age IS 'Age in years';\",\n  \"COMMENT ON COLUMN pg_diff_sync_test.people._created IS 'Timestamp for when this record was created';\",\n  \"COMMENT ON COLUMN pg_diff_sync_test.people._created_by IS 'UserID that created this record (if known)';\",\n  \"COMMENT ON COLUMN pg_diff_sync_test.people._modified IS 'Timestamp for when this record was last updated';\",\n  \"COMMENT ON COLUMN pg_diff_sync_test.people._modified_by IS 'UserID that last modified this record (if known)';\",\n  \"ALTER TABLE pg_diff_sync_test.people ADD PRIMARY KEY (employee_no);\",\n  \"CREATE UNIQUE INDEX people_first_name_last_name_idx ON pg_diff_sync_test.people (first_name,last_name);\"\n]\n```\n\n## \u003ca name=\"test\"\u003e\u003c/a\u003eTesting\n\n\n```bash\n$ npm test\n```\n\n## \u003ca name=\"license\"\u003e\u003c/a\u003eLicense\n[MIT](https://github.com/wmfs/pg-diff-sync/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmfs%2Fpg-diff-sync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwmfs%2Fpg-diff-sync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmfs%2Fpg-diff-sync/lists"}