-
Notifications
You must be signed in to change notification settings - Fork 181
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
Config file and type shorthands #91
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small details to fix in the comments.
otherwise LGTM.
README.md
Outdated
@@ -76,11 +79,26 @@ You can adjust defaults by passing arguments to `pg-migrate`: | |||
|
|||
See all by running `pg-migrate --help`. | |||
|
|||
Most of configuration options can be also specified in `node-config` configuration file. | |||
Most of configuration options can be also specified in [config](https://www.npmjs.com/package/config) configuration file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config configuration file?
---> I would omit the middle "configuration" word here.
|
||
* `migrations-dir`, `migrations-schema`, `migrations-table`, `check-order` - same as above | ||
|
||
* either `url` or [`user`], [`password`], `host` (defaults to localhost), `port` (defaults to 5432), `name` - for connection details |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is user
and password
in square brackets here?
should it read:
either url
, or [user
, password
, host
(...), port
, name
] - for connection details
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means that user and password are optional (you can have user without password and if you do not specify user, logged in user is used)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha, OK :-)
|
||
* `type-shorthands` - for column type shorthands | ||
|
||
You can specify custom types which will be expanded to column definition (e.g. for `module.exports = { "type-shorthands": { id: { type: 'uuid', primaryKey: true }, createdAt: { type: 'timestamp', notNull: true, default: new require('node-pg-migrate').PgLiteral('current_timestamp') } } }` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the bracket before "e.g." is not closed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone provide a real example of how to use this feature? I have been trying in different ways without any success.
Thank you
README.md
Outdated
* `type-shorthands` - for column type shorthands | ||
|
||
You can specify custom types which will be expanded to column definition (e.g. for `module.exports = { "type-shorthands": { id: { type: 'uuid', primaryKey: true }, createdAt: { type: 'timestamp', notNull: true, default: new require('node-pg-migrate').PgLiteral('current_timestamp') } } }` | ||
will in `pgm.createTable('test', { id: 'id', createdAt: 'createdAt' });` produce SQL `CREATE TABLE "test" ("id" uuid PRIMARY KEY, "createdAt" timestamp DEFAULT current_timestamp NOT NULL);`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I would say "it will in ..." instead of just "will in".
@mzuniga84
Run it as |
Would there be any way to "version" this shorthand file in tandem with migrations? As in, I want to record in my migrations when these shorthands change, as changing this file necessarily breaks all migrations dependent on it. |
That's true :(
What do you think @flux627 ? |
I would prefer a multi-file solution to both match the migrations pattern and keep things clear. Maybe if you specify a directory instead of a file, it can parse a timestamp at the beginning of the string and use the most recent definitions for a given migration timestamp. At that point though, I think it would make much more sense to define these shorthands within the migration files themselves. Something like:
It then would share these definitions for subsequent migrations, unless they are updated. If this was implemented I would be a very happy camper :) |
With this, if you wanted to, you could even have migrations files dedicated to shorthand updates, which would arguably be much cleaner. |
Fixes #87