Closed zilkey closed 6 years ago
You're using the migrations in a wrong way!
This should be like this instead:
'use strict';
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
exports.up = function(db) {
return db.createTable( 'product_variant',
{
id:
{
type: 'int',
unsigned: true,
notNull: true,
primaryKey: true,
autoIncrement: true,
length: 10
},
product_id:
{
type: 'int',
unsigned: true,
length: 10,
notNull: true,
foreignKey: {
name: 'product_variant_product_id_fk',
table: 'product',
rules: {
onDelete: 'CASCADE',
onUpdate: 'RESTRICT'
},
mapping: 'id'
}
},
});
};
exports.down = function(db) {
return null;
};
the createTable method returns a Promise, also to ask: Do you use v0.10.x-beta already, this is not true for v0.9.x though.
And yes you're absolutely right, I'm currently mainly focusing on the docs and think a lot about how to structure them better and make the entrance as easy as possible. Up to the final release of v0.10.x the docs should be up to date though.
For the real issue with this issue, this needs that to be added to the pg driver.
this bug is still hapening
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
When using the postgres driver, and using the migration from the docs:
And you run it with
node node_modules/.bin/db-migrate up
you'll get:When you run it with
node node_modules/.bin/db-migrate up --dry-run
you'll see:Notice the
"id" (10)
in there. It's caused by this line:https://github.com/db-migrate/pg/blob/master/index.js#L43
If autoincrement is true,
type
is an empty string. If you leave thelimit
off, it produces this:Solution 1
Raise an error when both are specified.
There's no real reason to specify a length and autoincrement. Postgres allows you to specify
bigserial
as a datatype, but does not (to my knowledge) allow you to specify a serial/bigserial table with a length.Solution 2
Silently ignore / warn users when length + autoincrement are specified in postgres.
Solution 3
Any other ideas?
Regardless, it seems like we should update the docs to not use the combination, since it's a bummer for new users when they copy the example and it blows up.
I'm happy to write the tests / submit the pull request / update the docs, but would like some guidance on how to handle this case.
Thanks!