wip: get app version from db.
This commit is contained in:
@@ -33,6 +33,7 @@ void main(List<String> args) async {
|
||||
SchemeMigration(),
|
||||
DownloadHistoryMigration(),
|
||||
LikeRecordMigration(),
|
||||
AppVersionMigration(),
|
||||
]);
|
||||
await runMigrations(migrationRunner, args);
|
||||
}
|
||||
@@ -64,3 +65,30 @@ Future doUserSeed() async {
|
||||
}
|
||||
return connection.close();
|
||||
}
|
||||
|
||||
class AppVersionSeed extends Migration {
|
||||
@override
|
||||
void up(Schema schema) async {
|
||||
await doAppVersionSeed();
|
||||
}
|
||||
|
||||
@override
|
||||
void down(Schema schema) async {}
|
||||
}
|
||||
|
||||
Future doAppVersionSeed() async {
|
||||
var connection = await connectToPostgres(configuration);
|
||||
await connection.open();
|
||||
var executor = PostgreSqlExecutor(connection);
|
||||
var appVersionQuery = AppVersionQuery();
|
||||
var one = await appVersionQuery.getOne(executor);
|
||||
if (one.isEmpty) {
|
||||
appVersionQuery = AppVersionQuery();
|
||||
appVersionQuery.values.copyFrom(AppVersion(
|
||||
versionCode: 1,
|
||||
versionName: '1.0.0',
|
||||
));
|
||||
return appVersionQuery.insert(executor).then((value) => connection.close());
|
||||
}
|
||||
return connection.close();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
import 'package:angel3_orm/angel3_orm.dart';
|
||||
import 'package:angel3_serialize/angel3_serialize.dart';
|
||||
import 'package:dde_gesture_manager_api/src/models/base_model.dart';
|
||||
import 'package:angel3_migration/angel3_migration.dart';
|
||||
import 'package:optional/optional.dart';
|
||||
part 'app_version.g.dart';
|
||||
|
||||
@serializable
|
||||
abstract class _AppVersion {
|
||||
@orm
|
||||
abstract class _AppVersion extends BaseModel {
|
||||
@SerializableField(isNullable: false)
|
||||
@Column(isNullable: false)
|
||||
String? get versionName;
|
||||
|
||||
@SerializableField(isNullable: false)
|
||||
@Column(isNullable: false)
|
||||
int? get versionCode;
|
||||
}
|
||||
|
||||
@serializable
|
||||
@Orm(tableName: 'app_versions', generateMigrations: false)
|
||||
abstract class _AppVersionResp {
|
||||
@SerializableField(isNullable: false)
|
||||
String? get versionName;
|
||||
|
||||
|
||||
@@ -3,24 +3,18 @@ import 'dart:async';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:dde_gesture_manager_api/apis.dart';
|
||||
import 'package:dde_gesture_manager_api/src/models/app_version.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
late FileSystem fs;
|
||||
import 'controller_extensions.dart';
|
||||
|
||||
Future configureServer(Angel app) async {
|
||||
app.get(
|
||||
Apis.system.appVersion,
|
||||
(req, res) async {
|
||||
var pubspec = fs.currentDirectory.parent.childDirectory('app').childFile('pubspec.yaml').readAsStringSync();
|
||||
var version = loadYaml(pubspec)['version'] as String;
|
||||
var versions = version.split('+');
|
||||
return res.json(AppVersion(versionName: versions.first, versionCode: int.parse(versions.last)));
|
||||
var appVersionQuery = AppVersionQuery();
|
||||
appVersionQuery.orderBy(AppVersionFields.versionCode, descending: true);
|
||||
return appVersionQuery.getOne(req.queryExecutor).then((value) => AppVersionResp(
|
||||
versionName: value.value.versionName,
|
||||
versionCode: value.value.versionCode,
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
configureServerWithFileSystem(FileSystem fileSystem) {
|
||||
fs = fileSystem;
|
||||
return configureServer;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ AngelConfigurer configureServer(FileSystem fileSystem) {
|
||||
});
|
||||
|
||||
// Typically, you want to mount controllers first, after any global middleware.
|
||||
await app.configure(system_controllers.configureServerWithFileSystem(fileSystem));
|
||||
await app.configure(system_controllers.configureServer);
|
||||
await app.configure(auth_controllers.configureServer);
|
||||
await app.configure(scheme_controllers.configureServer);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ dependencies:
|
||||
belatuk_pretty_logging: ^4.0.0
|
||||
optional: ^6.0.0
|
||||
logging: ^1.0.0
|
||||
yaml: ^3.1.0
|
||||
mailer: ^5.0.2
|
||||
uuid: ^3.0.5
|
||||
neat_cache:
|
||||
|
||||
Reference in New Issue
Block a user