get app version from db. #8
@@ -33,6 +33,7 @@ void main(List<String> args) async {
|
|||||||
SchemeMigration(),
|
SchemeMigration(),
|
||||||
DownloadHistoryMigration(),
|
DownloadHistoryMigration(),
|
||||||
LikeRecordMigration(),
|
LikeRecordMigration(),
|
||||||
|
AppVersionMigration(),
|
||||||
]);
|
]);
|
||||||
await runMigrations(migrationRunner, args);
|
await runMigrations(migrationRunner, args);
|
||||||
}
|
}
|
||||||
@@ -64,3 +65,30 @@ Future doUserSeed() async {
|
|||||||
}
|
}
|
||||||
return connection.close();
|
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: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';
|
part 'app_version.g.dart';
|
||||||
|
|
||||||
@serializable
|
@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)
|
@SerializableField(isNullable: false)
|
||||||
String? get versionName;
|
String? get versionName;
|
||||||
|
|
||||||
|
|||||||
@@ -3,24 +3,18 @@ import 'dart:async';
|
|||||||
import 'package:angel3_framework/angel3_framework.dart';
|
import 'package:angel3_framework/angel3_framework.dart';
|
||||||
import 'package:dde_gesture_manager_api/apis.dart';
|
import 'package:dde_gesture_manager_api/apis.dart';
|
||||||
import 'package:dde_gesture_manager_api/src/models/app_version.dart';
|
import 'package:dde_gesture_manager_api/src/models/app_version.dart';
|
||||||
import 'package:file/file.dart';
|
import 'controller_extensions.dart';
|
||||||
import 'package:yaml/yaml.dart';
|
|
||||||
|
|
||||||
late FileSystem fs;
|
|
||||||
|
|
||||||
Future configureServer(Angel app) async {
|
Future configureServer(Angel app) async {
|
||||||
app.get(
|
app.get(
|
||||||
Apis.system.appVersion,
|
Apis.system.appVersion,
|
||||||
(req, res) async {
|
(req, res) async {
|
||||||
var pubspec = fs.currentDirectory.parent.childDirectory('app').childFile('pubspec.yaml').readAsStringSync();
|
var appVersionQuery = AppVersionQuery();
|
||||||
var version = loadYaml(pubspec)['version'] as String;
|
appVersionQuery.orderBy(AppVersionFields.versionCode, descending: true);
|
||||||
var versions = version.split('+');
|
return appVersionQuery.getOne(req.queryExecutor).then((value) => AppVersionResp(
|
||||||
return res.json(AppVersion(versionName: versions.first, versionCode: int.parse(versions.last)));
|
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.
|
// 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(auth_controllers.configureServer);
|
||||||
await app.configure(scheme_controllers.configureServer);
|
await app.configure(scheme_controllers.configureServer);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ dependencies:
|
|||||||
belatuk_pretty_logging: ^4.0.0
|
belatuk_pretty_logging: ^4.0.0
|
||||||
optional: ^6.0.0
|
optional: ^6.0.0
|
||||||
logging: ^1.0.0
|
logging: ^1.0.0
|
||||||
yaml: ^3.1.0
|
|
||||||
mailer: ^5.0.2
|
mailer: ^5.0.2
|
||||||
uuid: ^3.0.5
|
uuid: ^3.0.5
|
||||||
neat_cache:
|
neat_cache:
|
||||||
|
|||||||
Reference in New Issue
Block a user