multum / pg-differ Goto Github PK
View Code? Open in Web Editor NEWNode.js migration tool for PostgreSQL
Home Page: https://multum.github.io/pg-differ
License: MIT License
Node.js migration tool for PostgreSQL
Home Page: https://multum.github.io/pg-differ
License: MIT License
This error occurs when trying to synchronize tables in the _normalizeCheckRows
method
// v1.x
{
table: 'table_name',
columns: {},
...
}
// v2.0
{
type: 'table', // table, sequence and more
properties: {
name: 'table_name',
columns: {},
...
}
}
// v1.x
{
table: 'table_name',
indexes: [],
forceIndexes: [ 'foreignKey', 'primaryKey' ],
columns: [
{
name: 'column_name',
primaryKey: true,
references: { ... },
onUpdate,
....
}
]
}
// v2.0
{
type: 'table',
properties: {
name: 'table_name',
cleanable: {
foreignKeys: true,
primaryKeys: true,
},
indexes: [],
primaryKeys: [],
unique: [],
foreignKeys: [
{
columns: [ 'column_name' ]
references: { ... },
onUpdate,
....,
},
],
columns: [
{
name: 'column_name',
primaryKey: true,
},
],
},
}
Drop and create sequences by synchronizing the table with force mode
CHECK
constraint
Currently the definition of columns is an object. So the order is not really specified. I think this is an opportunity for this package to create columns in the best order so that data is packed optimally. See more information here: https://www.2ndquadrant.com/en/blog/on-rocks-and-sand/
The issue is that reordering of columns is not yet possible: https://wiki.postgresql.org/wiki/Alter_column_position For now a table has to be recreated. I think this could be an opt-in feature of this package to also do for you.
An error occurs when creating a large number of SQL queries in one transaction to update the database
Optimize the structure and change the approach in the tests. It would be nice to check the SQL
queries that were executed to update the database(after the closure of issue #79)
column.force
parameter to avoid data lossconst differ = new Differ({ ... })
const schema = await differ.read.table({ name: 'public.users' })
In documentation, there is example when column can be defined as string:
description: 'character varying(255)'
This does not pass type checking based on current typing information.
When adding the identity
property to a column, we need to delete the old sequence that was previously created for this column (when it had the serial
type)
How to rename a column (or table)?
I think this project is great, but I could not find a way to rename a column (or table)? I think probably some option like oldNames
could be provided for both columns and tables which would then rename them if Differ detects anything under the old name.
(This would not allow one to reuse the old name, but I think this is probably OK limitation for this project.)
fs
methods in differ.import()
pg-differ generate -p ./schemas -c ${connectionString} --table public.users
{
"type": "table",
"properties": {
"name": "public.users",
"columns": {
"id": "bigint",
"birthday": "timestamp" // instead "timestamp without time zone"
}
}
}
const differ = new Differ({ ... });
const chats = differ.define('table', { name: 'chats', columns: [ ... ] });
console.log(chats.getFullName()) // 'public.chats'`
differ.setDefaultSchema('user_schema');
console.log(chats.getFullName()) // 'user_schema.chats'
const differ = new Differ({ ... });
differ.import(...)
const changes = differ.sync({ execute: true })
/**
[
alter table "public"."users" add primary key ("id");
...
]
*/
const tableChanges = changes.filter((query) => {
return /"public"."users"/.test(query)
})
const hasBeenChanged = tableChanges.length !== 0
const primaryKeyHasBeenAdded = Boolean(tableChanges.find((query) => {
return /add primary key/i.test(query)
}))
While attempting to test the pg-differ
cli on Macos, I ran into a env: node\r: No such file or directory
error.
I was able to resolve the issue by following the instructions in this S.O. answer. The problem is apparently caused because the pg-differ
CLI source code file has windows style line endings.
Need to add the ability to rename table columns
Converting values without removing them when changing the type of the column 'boolean' => 'integer' and 'integer' => 'boolean'
Restart the sequence to the largest column value that uses this sequence
So I think it is OK that removed columns are kept. But they should be changed so that NULL values can be inserted into them. This means that future queries which do not know about those columns can succeed and database will just insert NULL values in their place.
match
parameter will be used to filter synchronization objects and take the regular expression as a valueconst differ = new Differ({...})
differ.define('table', { name: 'contacts', columns: {...} }) // will be sync
differ.define('table', { name: 'contact_roles', columns: {...} }) // will be sync
differ.define('table', { name: 'chats', columns: {...} }) // will not sync
await differ.sync({ match: /^contact.*/ })
Need to add the .d.ts declaration file and remove the JSDoc comments
const differ = new Differ(...)
differ.define('table', {
name: 'CamelCaseSchema.Roles',
columns: [ { name: 'ID', type: 'bigint' }, { name: 'type', type: 'smallint' } ]
})
differ.sync().then(console.log)
/*
[
'create table "CamelCaseSchema"."Roles" ( "ID" bigint, "type" smallint );'
]
*/
schemaFolder
optionplaceholders
optionforce
from constructor optionsSeeds
objectseeds
option from Table
objectA declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.