2016-03-02 17:07:05 +01:00
|
|
|
|
|
|
|
// MySQL Schema Compiler
|
|
|
|
// -------
|
2016-05-17 01:01:34 +10:00
|
|
|
import inherits from 'inherits';
|
|
|
|
import SchemaCompiler from '../../../schema/compiler';
|
2016-03-02 17:07:05 +01:00
|
|
|
|
2016-05-18 20:22:50 +10:00
|
|
|
import { assign } from 'lodash'
|
2016-03-02 17:07:05 +01:00
|
|
|
|
|
|
|
function SchemaCompiler_MySQL(client, builder) {
|
|
|
|
SchemaCompiler.call(this, client, builder)
|
|
|
|
}
|
|
|
|
inherits(SchemaCompiler_MySQL, SchemaCompiler)
|
|
|
|
|
|
|
|
assign(SchemaCompiler_MySQL.prototype, {
|
|
|
|
|
|
|
|
// Rename a table on the schema.
|
2016-05-17 01:01:34 +10:00
|
|
|
renameTable(tableName, to) {
|
|
|
|
this.pushQuery(`rename table ${this.formatter.wrap(tableName)} to ${this.formatter.wrap(to)}`);
|
2016-03-02 17:07:05 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Check whether a table exists on the query.
|
2016-05-17 01:01:34 +10:00
|
|
|
hasTable(tableName) {
|
2016-03-02 17:07:05 +01:00
|
|
|
this.pushQuery({
|
2016-05-17 01:01:34 +10:00
|
|
|
sql: `show tables like ${this.formatter.parameter(tableName)}`,
|
|
|
|
output(resp) {
|
2016-03-02 17:07:05 +01:00
|
|
|
return resp.length > 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Check whether a column exists on the schema.
|
2016-05-17 01:01:34 +10:00
|
|
|
hasColumn(tableName, column) {
|
2016-03-02 17:07:05 +01:00
|
|
|
this.pushQuery({
|
2016-05-17 01:01:34 +10:00
|
|
|
sql: `show columns from ${this.formatter.wrap(tableName)}` +
|
2016-03-02 17:07:05 +01:00
|
|
|
' like ' + this.formatter.parameter(column),
|
2016-05-17 01:01:34 +10:00
|
|
|
output(resp) {
|
2016-03-02 17:07:05 +01:00
|
|
|
return resp.length > 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
2016-05-17 01:01:34 +10:00
|
|
|
export default SchemaCompiler_MySQL;
|