Updated Angel3 migration

This commit is contained in:
Thomas Hii 2024-07-19 07:43:29 +08:00
parent 2510b76e80
commit cb25da3077
13 changed files with 178 additions and 22 deletions

View file

@ -1,6 +1,6 @@
# Runing Ancillary Docker Services # Docker Services
The required ancillary services required by the framework can be run using the compose files provided in this folder. The required applications by the framework can be run using the docker compose files provided in this folder.
## PostreSQL ## PostreSQL

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 8.2.1
* Updated README
## 8.2.0 ## 8.2.0
* Require Dart >= 3.3 * Require Dart >= 3.3

View file

@ -5,15 +5,9 @@
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM) [![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration/LICENSE) [![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration/LICENSE)
A basic database migration framework built for Angel3 ORM. This package contains the abstract classes for implementing database migration in Angel3 framework. It is designed to work with Angel3 ORM. Please refer to the implementation in the [ORM Migration Runner](<https://pub.dev/packages/angel3_migration_runner>) package for more details.
## Supported database ## Supported Features
* PostgreSQL version 10 or later
* MariaDB 10.2.x or later
* MySQL 8.x or later
## Features
* Create tables based on ORM models * Create tables based on ORM models
* Drop tables based on ORM models * Drop tables based on ORM models
@ -21,4 +15,4 @@ A basic database migration framework built for Angel3 ORM.
## Limitation ## Limitation
* Alter table/fields based on updated ORM models not supported * Alter table/fields based on updated ORM models is not supported

View file

@ -1,6 +1,6 @@
name: angel3_migration name: angel3_migration
version: 8.2.0 version: 8.2.1
description: Database migration runtime for Angel3 ORM. Use this package to define schemas. description: The abstract classes for implementing database migration in Angel3 framework. Designed to work with Angel3 ORM.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration repository: https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration
environment: environment:

View file

@ -1,5 +1,12 @@
# Change Log # Change Log
## 8.2.1
* Updated README
* Added test cases for `PostgreSQL`
* Added test cases for `MySQL`
* Added test cases for `MariaDB`
## 8.2.0 ## 8.2.0
* Require Dart >= 3.3 * Require Dart >= 3.3

View file

@ -5,9 +5,7 @@
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM) [![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
[![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration_runner/LICENSE) [![License](https://img.shields.io/github/license/dart-backend/angel)](https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration_runner/LICENSE)
Database migration runner for Angel3 ORM. This package contains the implementation of the database migration for the following databases. It is designed to work with Angel3 ORM.
Supported database:
* PostgreSQL 10.x or greater * PostgreSQL 10.x or greater
* MariaDB 10.2.x or greater * MariaDB 10.2.x or greater

View file

@ -17,8 +17,8 @@ class MariaDbMigrationRunner implements MigrationRunner {
MariaDbMigrationRunner(this.connection, MariaDbMigrationRunner(this.connection,
{Iterable<Migration> migrations = const [], bool connected = false}) { {Iterable<Migration> migrations = const [], bool connected = false}) {
if (migrations.isNotEmpty == true) migrations.forEach(addMigration); if (migrations.isNotEmpty) migrations.forEach(addMigration);
_connected = connected == true; _connected = connected;
} }
@override @override

View file

@ -17,8 +17,10 @@ class MySqlMigrationRunner implements MigrationRunner {
MySqlMigrationRunner(this.connection, MySqlMigrationRunner(this.connection,
{Iterable<Migration> migrations = const [], bool connected = false}) { {Iterable<Migration> migrations = const [], bool connected = false}) {
if (migrations.isNotEmpty == true) migrations.forEach(addMigration); if (migrations.isNotEmpty) {
_connected = connected == true; migrations.forEach(addMigration);
}
_connected = connected;
} }
@override @override

View file

@ -1,6 +1,6 @@
name: angel3_migration_runner name: angel3_migration_runner
version: 8.2.0 version: 8.2.1
description: Command-line based database migration runner for Angel3's ORM. description: The implementation of database migration for Angel3 framework. Designed to work with Angel3 ORM.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration_runner repository: https://github.com/dart-backend/angel/tree/master/packages/orm/angel_migration_runner
environment: environment:
@ -16,6 +16,7 @@ dependencies:
logging: ^1.2.0 logging: ^1.2.0
dev_dependencies: dev_dependencies:
lints: ^4.0.0 lints: ^4.0.0
test: ^1.25.0
# dependency_overrides: # dependency_overrides:
# angel3_orm: # angel3_orm:
# path: ../angel_orm # path: ../angel_orm

View file

@ -0,0 +1,31 @@
import 'dart:io';
import 'package:mysql1/mysql1.dart';
import 'package:test/test.dart';
void main() async {
late MySqlConnection conn;
setUp(() 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';
var settings = ConnectionSettings(
host: host,
port: 3306,
db: database,
user: username,
password: password);
conn = await MySqlConnection.connect(settings);
});
group('MariaDB', () {
test('migrate tables', () async {});
});
tearDown(() async {
await conn.close();
});
}

View file

@ -0,0 +1,53 @@
import 'package:angel3_migration/angel3_migration.dart';
import 'package:angel3_orm/angel3_orm.dart';
class UserMigration implements Migration {
@override
void up(Schema schema) {
schema.create('users', (table) {
table
..serial('id').primaryKey()
..varChar('username', length: 32).unique()
..varChar('password')
..boolean('account_confirmed').defaultsTo(false);
});
}
@override
void down(Schema schema) {
schema.drop('users');
}
}
class TodoMigration implements Migration {
@override
void up(Schema schema) {
schema.create('todos', (table) {
table
..serial('id').primaryKey()
..integer('user_id').references('users', 'id').onDeleteCascade()
..varChar('text')
..boolean('completed').defaultsTo(false);
});
}
@override
void down(Schema schema) {
schema.drop('todos');
}
}
class ItemMigration extends Migration {
@override
void up(Schema schema) {
schema.create('items', (table) {
table
..serial('id').primaryKey()
..varChar('name', length: 64)
..timeStamp('created_at').defaultsTo(currentTimestamp);
});
}
@override
void down(Schema schema) => schema.drop('items');
}

View file

@ -0,0 +1,34 @@
import 'dart:io';
import 'package:mysql_client/mysql_client.dart';
import 'package:test/test.dart';
void main() async {
late MySQLConnection conn;
setUp(() 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';
var secure = !('false' == Platform.environment['MYSQL_SECURE']);
print("$host $database $username $password $secure");
conn = await MySQLConnection.createConnection(
databaseName: database,
port: 3306,
host: host,
userName: username,
password: password,
secure: secure);
});
group('Mysql', () {
test('migrate tables', () async {});
});
tearDown(() async {
await conn.close();
});
}

View file

@ -0,0 +1,32 @@
import 'dart:io';
import 'package:postgres/postgres.dart';
import 'package:test/test.dart';
void main() async {
late Connection conn;
setUp(() async {
var host = Platform.environment['POSTGRES_HOST'] ?? 'localhost';
var database = Platform.environment['POSTGRES_DB'] ?? 'orm_test';
var username = Platform.environment['POSTGRES_USERNAME'] ?? 'test';
var password = Platform.environment['POSTGRES_PASSWORD'] ?? 'test123';
print("$host $database $username $password");
conn = await Connection.open(Endpoint(
host: host,
port: 5432,
database: database,
username: username,
password: password));
});
group('PostgreSQL', () {
test('migrate tables', () async {});
});
tearDown(() async {
await conn.close();
});
}