Merge pull request #146 from Garthi/feature/migration_index_upgrade
index handling for after table
This commit is contained in:
commit
6bf4ad4b9e
4 changed files with 109 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
|
|
||||||
import 'column.dart';
|
import 'column.dart';
|
||||||
|
|
||||||
abstract class Table {
|
abstract class Table {
|
||||||
|
@ -49,4 +50,7 @@ abstract class MutableTable extends Table {
|
||||||
void changeColumnType(String name, ColumnType type);
|
void changeColumnType(String name, ColumnType type);
|
||||||
void dropNotNull(String name);
|
void dropNotNull(String name);
|
||||||
void setNotNull(String name);
|
void setNotNull(String name);
|
||||||
|
void addIndex(String name, List<String> columns, IndexType type);
|
||||||
|
void dropIndex(String name);
|
||||||
|
void dropPrimaryIndex();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
|
||||||
import 'package:angel3_migration/angel3_migration.dart';
|
import 'package:angel3_migration/angel3_migration.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
import 'package:charcode/ascii.dart';
|
import 'package:charcode/ascii.dart';
|
||||||
|
|
||||||
abstract class MariaDbGenerator {
|
abstract class MariaDbGenerator {
|
||||||
|
@ -194,4 +195,37 @@ class MariaDbAlterTable extends Table implements MutableTable {
|
||||||
void rename(String newName) {
|
void rename(String newName) {
|
||||||
_stack.add('RENAME TO $newName');
|
_stack.add('RENAME TO $newName');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void addIndex(String name, List<String> columns, IndexType type) {
|
||||||
|
String indexType = '';
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case IndexType.primaryKey:
|
||||||
|
indexType = 'PRIMARY KEY';
|
||||||
|
break;
|
||||||
|
case IndexType.unique:
|
||||||
|
indexType = 'UNIQUE INDEX IF NOT EXISTS `$name`';
|
||||||
|
break;
|
||||||
|
case IndexType.standardIndex:
|
||||||
|
case IndexType.none:
|
||||||
|
indexType = 'INDEX IF NOT EXISTS `$name`';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mask the column names, is more safety
|
||||||
|
columns.map((column) => '`$column`');
|
||||||
|
|
||||||
|
_stack.add('ADD $indexType (${columns.join(',')})');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dropIndex(String name) {
|
||||||
|
_stack.add('DROP INDEX IF EXISTS `$name`');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dropPrimaryIndex() {
|
||||||
|
_stack.add('DROP PRIMARY KEY');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
|
||||||
import 'package:angel3_migration/angel3_migration.dart';
|
import 'package:angel3_migration/angel3_migration.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
import 'package:charcode/ascii.dart';
|
import 'package:charcode/ascii.dart';
|
||||||
|
|
||||||
abstract class MySqlGenerator {
|
abstract class MySqlGenerator {
|
||||||
|
@ -200,4 +201,37 @@ class MysqlAlterTable extends Table implements MutableTable {
|
||||||
void rename(String newName) {
|
void rename(String newName) {
|
||||||
_stack.add('RENAME TO $newName');
|
_stack.add('RENAME TO $newName');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void addIndex(String name, List<String> columns, IndexType type) {
|
||||||
|
String indexType = '';
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case IndexType.primaryKey:
|
||||||
|
indexType = 'PRIMARY KEY';
|
||||||
|
break;
|
||||||
|
case IndexType.unique:
|
||||||
|
indexType = 'UNIQUE INDEX `$name`';
|
||||||
|
break;
|
||||||
|
case IndexType.standardIndex:
|
||||||
|
case IndexType.none:
|
||||||
|
indexType = 'INDEX `$name`';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mask the column names, is more safety
|
||||||
|
columns.map((column) => '`$column`');
|
||||||
|
|
||||||
|
_stack.add('ADD $indexType (${columns.join(',')})');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dropIndex(String name) {
|
||||||
|
_stack.add('DROP INDEX `$name`');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dropPrimaryIndex() {
|
||||||
|
_stack.add('DROP PRIMARY KEY');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'package:angel3_orm/angel3_orm.dart';
|
|
||||||
import 'package:angel3_migration/angel3_migration.dart';
|
import 'package:angel3_migration/angel3_migration.dart';
|
||||||
|
import 'package:angel3_orm/angel3_orm.dart';
|
||||||
import 'package:charcode/ascii.dart';
|
import 'package:charcode/ascii.dart';
|
||||||
|
|
||||||
abstract class PostgresGenerator {
|
abstract class PostgresGenerator {
|
||||||
|
@ -165,4 +166,37 @@ class PostgresAlterTable extends Table implements MutableTable {
|
||||||
void rename(String newName) {
|
void rename(String newName) {
|
||||||
_stack.add('RENAME TO "$newName"');
|
_stack.add('RENAME TO "$newName"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void addIndex(String name, List<String> columns, IndexType type) {
|
||||||
|
String indexType = '';
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case IndexType.primaryKey:
|
||||||
|
indexType = 'PRIMARY KEY';
|
||||||
|
break;
|
||||||
|
case IndexType.unique:
|
||||||
|
indexType = 'CONSTRAINT "$name" UNIQUE';
|
||||||
|
break;
|
||||||
|
case IndexType.standardIndex:
|
||||||
|
case IndexType.none:
|
||||||
|
// not working with postgres
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mask the column names, is more safety
|
||||||
|
columns.map((column) => '"$column"');
|
||||||
|
|
||||||
|
_stack.add('ADD $indexType (${columns.join(',')})');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dropIndex(String name) {
|
||||||
|
_stack.add('DROP CONSTRAINT "$name"');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dropPrimaryIndex() {
|
||||||
|
_stack.add('DROP CONSTRAINT "${tableName}_pkey"');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue