-
-
Notifications
You must be signed in to change notification settings - Fork 360
How to query exist data before migration #248
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
Comments
Data operations are not exactly a part of the migrations. This more or less belongs to seeding data. Yet you can't select data, but there are features which are going to be introduced within v0.10.x and this: So currently you can't do this via any method which is intended to do this. But this doesn't mean it is impossible. You need to fallback to runSql and select your data by native queries, but why you don't just add a defaultValue to your definition. With a defaultValue you can set notNull to true unless it is keyed with unique or primary. |
@wzrdtales yes, The new column is for unique values |
Then you need to fallback to runSql right now. |
Thanks that was what I did? For example exports.up = function (db, callback) {
async.series([
db.addColumn.bind(db, 'users', 'email', {
type: type.STRING
}),
function (cb) {
return db.runSql('SELECT * FROM users', [], function (err, results) {
var inserts = [];
results.rows.forEach(function (row) {
inserts.push(db.runSql.bind(
db, 'UPDATE users SET email = ? WHERE id = ?', [row.username + '@example.com', row.id]
));
});
async.series(inserts, cb);
});
},
db.changeColumn.bind(db, 'users', 'email', {
type: type.STRING,
notNull: true
}),
db.addIndex.bind(db, 'users', 'email_unique', ['email'], true),
db.addIndex.bind(db, 'users', 'username_unique', ['username'], true)
], callback);
}; |
That is probably a solution, if this works for you. |
Example
I need add a new
notNull: true
column, but the table has rows. sonotNull: true
propertynotNull: true
How i can get the current data?
The text was updated successfully, but these errors were encountered: