platform/packages/orm/angel_migration/lib/src/table.dart

53 lines
1.7 KiB
Dart
Raw Normal View History

2021-05-17 15:34:19 +00:00
import 'package:angel3_orm/angel3_orm.dart';
2019-02-14 17:15:34 +00:00
import 'column.dart';
abstract class Table {
MigrationColumn declareColumn(String name, Column column);
MigrationColumn declare(String name, ColumnType type) =>
2021-05-17 15:34:19 +00:00
declareColumn(name, MigrationColumn(type));
2019-02-14 17:15:34 +00:00
MigrationColumn serial(String name) => declare(name, ColumnType.serial);
MigrationColumn integer(String name) => declare(name, ColumnType.int);
MigrationColumn float(String name) => declare(name, ColumnType.float);
2022-06-10 16:44:09 +00:00
MigrationColumn double(String name) => declare(name, ColumnType.double);
MigrationColumn numeric(String name, {int precision = 17, int scale = 3}) {
return declare(name, ColumnType.numeric);
}
2019-02-14 17:15:34 +00:00
MigrationColumn boolean(String name) => declare(name, ColumnType.boolean);
MigrationColumn date(String name) => declare(name, ColumnType.date);
2022-02-07 12:42:32 +00:00
//@deprecated
//MigrationColumn dateTime(String name) => timeStamp(name, timezone: true);
2019-02-14 17:15:34 +00:00
2021-05-17 15:34:19 +00:00
MigrationColumn timeStamp(String name, {bool timezone = false}) {
2022-06-10 16:44:09 +00:00
if (!timezone) {
return declare(name, ColumnType.timeStamp);
}
2019-02-14 17:15:34 +00:00
return declare(name, ColumnType.timeStampWithTimeZone);
}
2019-04-26 14:44:25 +00:00
MigrationColumn text(String name) => declare(name, ColumnType.text);
2019-02-14 17:15:34 +00:00
2021-05-02 07:36:33 +00:00
MigrationColumn varChar(String name, {int? length}) {
2019-02-14 17:15:34 +00:00
if (length == null) return declare(name, ColumnType.varChar);
return declareColumn(
2021-05-17 15:34:19 +00:00
name, Column(type: ColumnType.varChar, length: length));
2019-02-14 17:15:34 +00:00
}
}
abstract class MutableTable extends Table {
void rename(String newName);
void dropColumn(String name);
void renameColumn(String name, String newName);
void changeColumnType(String name, ColumnType type);
void dropNotNull(String name);
void setNotNull(String name);
}