Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow shorthands to be defined within migration files #177

Closed
flux627 opened this issue Feb 5, 2018 · 1 comment
Closed

Allow shorthands to be defined within migration files #177

flux627 opened this issue Feb 5, 2018 · 1 comment

Comments

@flux627
Copy link
Contributor

flux627 commented Feb 5, 2018

As per the discussion in #91, currently, there is no mechanism to update shorthands in tandem with migrations, in the case where a field that uses a shorthand ever needs to change in the future. I propose that we allow the ability to define shorthands within migration files, so that they can be updated.

Since changing a shorthand doesn't actually change anything unless a migration is run that uses it, an explicit call to pgm.alterColumn will be required.

1234567890-create-user-table.js:

module.exports.shorthands = {
  id: {
    type: 'serial',
    primaryKey: true
  }
}

exports.up = (pgm) => {
  pgm.createTable( "users", {
    id: "id"
  }
}

1234567891-update-user-table.js:

module.exports.shorthands = {
  id: {
      type: "uuid",
      primaryKey: true,
    }
}

exports.up = (pgm) => {
  pgm.alterColumn( "users", "id", {
    id: "id"
  }
}

This also keeps all information relevant to migrations within the migration files. Discussion and/or improvements welcome.

@dolezel
Copy link
Contributor

dolezel commented Feb 6, 2018

👍 good idea
Will probably release it as version 3 - it is quite a change how configuration works right now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants