-
-
Notifications
You must be signed in to change notification settings - Fork 529
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 the Postgres schema for the migration table to be specified through migrationStorageTableSchema (#265) #635
Changes from 7 commits
4dfd1f9
00f5a7b
993625b
d6f74c3
8f5953f
074fd13
3007577
17c7f8c
f230710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,35 @@ const _ = require('lodash'); | |
}); | ||
}); | ||
}); | ||
|
||
describe('custom meta schema', () => { | ||
it('correctly uses the defined schema', function (done) { | ||
const self = this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
prepare(() => { | ||
if (Support.dialectIsPostgres()) { | ||
helpers.readSchemas(self.sequelize, schemas => { | ||
expect(schemas.sort()).to.eql(['sequelize_schema']); | ||
|
||
// Tables from public should still be the same. | ||
helpers.readTables(self.sequelize, tables => { | ||
expect(tables.sort()).to.eql(['Person', 'Task']); | ||
done(); | ||
}); | ||
}); | ||
} else { | ||
// If not Postgres, the schema option gets prepended to the table name. | ||
helpers.readTables(self.sequelize, tables => { | ||
expect(tables.sort()).to.eql(['Person', 'Task', 'sequelize_schema.SequelizeMeta']); | ||
done(); | ||
}); | ||
} | ||
}, { | ||
migrationFile: 'new/*createPerson', | ||
config: { migrationStorageTableSchema: 'sequelize_schema' } | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ var fs = require('fs'); | |
var path = require('path'); | ||
var Sequelize = require('sequelize'); | ||
var _ = require('lodash'); | ||
var Bluebird = require('bluebird'); | ||
var DataTypes = Sequelize; | ||
var Config = require(__dirname + '/config/config'); | ||
var expect = require('expect.js'); | ||
|
@@ -90,27 +91,55 @@ var Support = { | |
}, | ||
|
||
clearDatabase: function (sequelize, callback) { | ||
sequelize | ||
.getQueryInterface() | ||
.dropAllTables() | ||
.then(function () { | ||
if (sequelize.daoFactoryManager) { | ||
sequelize.daoFactoryManager.daos = []; | ||
} else { | ||
sequelize.modelManager.models = []; | ||
} | ||
|
||
return sequelize | ||
.getQueryInterface() | ||
.dropAllEnums() | ||
.then(callback) | ||
.catch(function (err) { | ||
console.log('Error in support.clearDatabase() dropAllEnums() :: ', err); | ||
function dropAllTables() { | ||
return sequelize | ||
.getQueryInterface() | ||
.dropAllTables() | ||
.then(function () { | ||
if (sequelize.daoFactoryManager) { | ||
sequelize.daoFactoryManager.daos = []; | ||
} else { | ||
sequelize.modelManager.models = []; | ||
} | ||
|
||
return sequelize | ||
.getQueryInterface() | ||
.dropAllEnums() | ||
.then(callback) | ||
.catch(function (err) { | ||
console.log('Error in support.clearDatabase() dropAllEnums() :: ', err); | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log('Error in support.clearDatabase() dropAllTables() :: ', err); | ||
}); | ||
}; | ||
|
||
// If Postgres, loop through each of the non-public schemas and DROP/re-CREATE them. | ||
if (this.dialectIsPostgres()) { | ||
sequelize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think tests are failing because of missing return |
||
.showAllSchemas() | ||
.then(function (schemas) { | ||
// showAllSchemas() leaves off the public schema. | ||
let searchPathSchemas = schemas.join(', '); | ||
let promise = Bluebird.resolve(); | ||
|
||
_.forEach(schemas, function (schema) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
promise = promise.then(function () { | ||
return sequelize | ||
.dropSchema(schema) | ||
.then(function() { | ||
return sequelize.createSchema(schema) | ||
}); | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log('Error in support.clearDatabase() dropAllTables() :: ', err); | ||
}); | ||
}); | ||
|
||
// Drop the public schema tables. | ||
promise.then(dropAllTables); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return the promise |
||
}); | ||
} else { | ||
return dropAllTables(); | ||
} | ||
}, | ||
|
||
getSupportedDialects: function () { | ||
|
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.
Use
createSchema
directly which handles existing schema withIF NOT EXISTS
https://github.com/sequelize/sequelize/blob/aa92764f953eeefbf194a6e2b765552adfa73bda/lib/query-interface.js#L35