Code Monkey home page Code Monkey logo

pg-differ's People

Contributors

multum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pg-differ's Issues

Roadmap for version 2.0

Planned Features

  1. Support for multiple Postges objects(table, sequence and more)
// v1.x
{
  table: 'table_name',
  columns: {},
  ...
}

// v2.0
{
  type: 'table', // table, sequence and more
  properties: {
    name: 'table_name',
    columns: {},
    ...
  }
}
  1. Indexes and constraints in the scheme are separated
// 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,
      },
    ],
  },
}

Nice to Have Features

  1. Drop and create sequences by synchronizing the table with force mode

  2. CHECK constraint

Optimize the order of columns

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.

Error: out of shared memory

An error occurs when creating a large number of SQL queries in one transaction to update the database

  • Need to group requests in small transactions

Refactor tests

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)

Roadmap for version 2.3 ⚡️

Planned Features

  1. Ability to read the structure of existing entities
const differ = new Differ({ ... })
const schema = await differ.read.table({ name: 'public.users' })

Typing for column does not allow a string

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.

Renaming a column (or table)

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.)

Roadmap for v4 ⚡️

Planned

  • remove deprecated features
  • add strict mode that converts warnings to errors
  • add the ability to set names for constraints and indexes
  • use async fs methods in differ.import()

Nice To Have

  • move CLI to a separate module

Type aliases in the 'generate' command

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"
    }
  }
}

Add 'setDefaultSchema' method

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'

Return object of changes as the result of 'sync' method execution

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)
}))

bug: pg-differ CLI has issues on Macos

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.

Removed columns should be made null-able

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.

Add 'match' parameter to 'sync' method

The match parameter will be used to filter synchronization objects and take the regular expression as a value

const 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.*/ })

Add support for 'quoted identifiers'

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 );'
]
*/

Remove deprecated and unnecessary code

  • remove the schemaFolder option
  • remove the placeholders option
  • remove force from constructor options
  • remove the Seeds object
  • remove the seeds option from Table object

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.