2024-02-12 04:31:33 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2021-05-18 14:47:56 +00:00
|
|
|
import 'package:angel3_migration/angel3_migration.dart';
|
|
|
|
import 'package:angel3_migration_runner/angel3_migration_runner.dart';
|
2024-07-20 02:23:45 +00:00
|
|
|
import 'package:angel3_migration_runner/mysql.dart';
|
2021-05-18 14:47:56 +00:00
|
|
|
import 'package:angel3_migration_runner/postgres.dart';
|
|
|
|
import 'package:angel3_orm/angel3_orm.dart';
|
2024-07-20 02:23:45 +00:00
|
|
|
import 'package:mysql_client/mysql_client.dart';
|
2019-02-14 17:15:34 +00:00
|
|
|
import 'package:postgres/postgres.dart';
|
2022-01-02 07:21:17 +00:00
|
|
|
|
2021-05-18 14:47:56 +00:00
|
|
|
import 'todo.dart';
|
2019-02-14 17:15:34 +00:00
|
|
|
|
2022-04-23 04:21:39 +00:00
|
|
|
void main(List<String> args) async {
|
2024-07-20 02:23:45 +00:00
|
|
|
// Run migration on PostgreSQL database
|
|
|
|
postgresqlMigration(args);
|
|
|
|
|
|
|
|
// Run migration on MySQL database
|
|
|
|
mysqlMigration(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void postgresqlMigration(List<String> args) async {
|
2024-02-12 04:31:33 +00:00
|
|
|
var host = Platform.environment['DB_HOST'] ?? 'localhost';
|
|
|
|
var database = Platform.environment['DB_NAME'] ?? 'demo';
|
|
|
|
var username = Platform.environment['DB_USERNAME'] ?? 'demouser';
|
|
|
|
var password = Platform.environment['DB_PASSWORD'] ?? 'demo123';
|
|
|
|
|
|
|
|
print("$host $database $username $password");
|
|
|
|
|
2024-07-20 02:23:45 +00:00
|
|
|
Connection conn = await Connection.open(
|
|
|
|
Endpoint(
|
|
|
|
host: host,
|
|
|
|
port: 5432,
|
|
|
|
database: database,
|
|
|
|
username: username,
|
|
|
|
password: password),
|
|
|
|
settings: ConnectionSettings(sslMode: SslMode.disable));
|
2024-01-25 04:14:23 +00:00
|
|
|
|
2024-07-20 02:23:45 +00:00
|
|
|
var runner = PostgresMigrationRunner(
|
2024-01-25 04:14:23 +00:00
|
|
|
conn,
|
2022-04-23 04:21:39 +00:00
|
|
|
migrations: [
|
|
|
|
UserMigration(),
|
|
|
|
TodoMigration(),
|
|
|
|
FooMigration(),
|
|
|
|
],
|
|
|
|
);
|
2022-01-02 07:21:17 +00:00
|
|
|
|
2024-07-20 02:23:45 +00:00
|
|
|
runMigrations(runner, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mysqlMigration(List<String> args) async {
|
|
|
|
var host = Platform.environment['MYSQL_HOST'] ?? 'localhost';
|
|
|
|
var database = Platform.environment['MYSQL_DB'] ?? 'orm_test';
|
|
|
|
var username = Platform.environment['MYSQL_USERNAME'] ?? 'test';
|
|
|
|
var password = Platform.environment['MYSQL_PASSWORD'] ?? 'test123';
|
|
|
|
|
2022-04-23 04:21:39 +00:00
|
|
|
var mySQLConn = await MySQLConnection.createConnection(
|
2024-02-12 04:31:33 +00:00
|
|
|
host: host,
|
2022-01-02 07:21:17 +00:00
|
|
|
port: 3306,
|
2024-02-12 04:31:33 +00:00
|
|
|
databaseName: database,
|
|
|
|
userName: username,
|
|
|
|
password: password,
|
2024-07-20 02:23:45 +00:00
|
|
|
secure: true);
|
2019-02-14 17:15:34 +00:00
|
|
|
|
2023-09-23 03:31:46 +00:00
|
|
|
// ignore: unused_local_variable
|
2024-07-20 02:23:45 +00:00
|
|
|
var runner = MySqlMigrationRunner(
|
2022-04-23 04:21:39 +00:00
|
|
|
mySQLConn,
|
|
|
|
migrations: [
|
|
|
|
UserMigration(),
|
|
|
|
TodoMigration(),
|
|
|
|
FooMigration(),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2024-07-20 02:23:45 +00:00
|
|
|
runMigrations(runner, args);
|
2022-04-23 04:21:39 +00:00
|
|
|
}
|
2019-04-04 20:30:53 +00:00
|
|
|
|
|
|
|
class FooMigration extends Migration {
|
|
|
|
@override
|
|
|
|
void up(Schema schema) {
|
|
|
|
schema.create('foos', (table) {
|
|
|
|
table
|
|
|
|
..serial('id').primaryKey()
|
|
|
|
..varChar('bar', length: 64)
|
|
|
|
..timeStamp('created_at').defaultsTo(currentTimestamp);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void down(Schema schema) => schema.drop('foos');
|
|
|
|
}
|