mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: integrate postgres storage (#2604)
* chore: env config * chore: get user workspace * feat: enable postgres storage * chore: add new env * chore: add set env ffi * chore: pass env before backend init * chore: update * fix: ci tests * chore: commit the generate env file * chore: remove unused import
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
export 'package:async/async.dart';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'package:appflowy_backend/rust_stream.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'dart:ffi';
|
||||
import 'env_serde.dart';
|
||||
import 'ffi.dart' as ffi;
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
@ -34,4 +36,9 @@ class FlowySDK {
|
||||
ffi.store_dart_post_cobject(NativeApi.postCObject);
|
||||
ffi.init_sdk(sdkDir.path.toNativeUtf8());
|
||||
}
|
||||
|
||||
void setEnv(AppFlowyEnv env) {
|
||||
final jsonStr = jsonEncode(env.toJson());
|
||||
ffi.set_env(jsonStr.toNativeUtf8());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'env_serde.l.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class AppFlowyEnv {
|
||||
final SupabaseConfiguration supabase_config;
|
||||
final SupabaseDBConfig supabase_db_config;
|
||||
|
||||
AppFlowyEnv(
|
||||
{required this.supabase_config, required this.supabase_db_config});
|
||||
|
||||
factory AppFlowyEnv.fromJson(Map<String, dynamic> json) =>
|
||||
_$AppFlowyEnvFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$AppFlowyEnvToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SupabaseConfiguration {
|
||||
final String url;
|
||||
final String key;
|
||||
final String jwt_secret;
|
||||
|
||||
SupabaseConfiguration(
|
||||
{required this.url, required this.key, required this.jwt_secret});
|
||||
|
||||
factory SupabaseConfiguration.fromJson(Map<String, dynamic> json) =>
|
||||
_$SupabaseConfigurationFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SupabaseConfigurationToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class SupabaseDBConfig {
|
||||
final String url;
|
||||
final String key;
|
||||
final String jwt_secret;
|
||||
final CollabTableConfig collab_table_config;
|
||||
|
||||
SupabaseDBConfig(
|
||||
{required this.url,
|
||||
required this.key,
|
||||
required this.jwt_secret,
|
||||
required this.collab_table_config});
|
||||
|
||||
factory SupabaseDBConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$SupabaseDBConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SupabaseDBConfigToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class CollabTableConfig {
|
||||
final String table_name;
|
||||
final bool enable;
|
||||
|
||||
CollabTableConfig({required this.table_name, required this.enable});
|
||||
|
||||
factory CollabTableConfig.fromJson(Map<String, dynamic> json) =>
|
||||
_$CollabTableConfigFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$CollabTableConfigToJson(this);
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'env_serde.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
AppFlowyEnv _$AppFlowyEnvFromJson(Map<String, dynamic> json) => AppFlowyEnv(
|
||||
supabase_config: SupabaseConfiguration.fromJson(
|
||||
json['supabase_config'] as Map<String, dynamic>),
|
||||
supabase_db_config: SupabaseDBConfig.fromJson(
|
||||
json['supabase_db_config'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$AppFlowyEnvToJson(AppFlowyEnv instance) =>
|
||||
<String, dynamic>{
|
||||
'supabase_config': instance.supabase_config,
|
||||
'supabase_db_config': instance.supabase_db_config,
|
||||
};
|
||||
|
||||
SupabaseConfiguration _$SupabaseConfigurationFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
SupabaseConfiguration(
|
||||
url: json['url'] as String,
|
||||
key: json['key'] as String,
|
||||
jwt_secret: json['jwt_secret'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SupabaseConfigurationToJson(
|
||||
SupabaseConfiguration instance) =>
|
||||
<String, dynamic>{
|
||||
'url': instance.url,
|
||||
'key': instance.key,
|
||||
'jwt_secret': instance.jwt_secret,
|
||||
};
|
||||
|
||||
SupabaseDBConfig _$SupabaseDBConfigFromJson(Map<String, dynamic> json) =>
|
||||
SupabaseDBConfig(
|
||||
url: json['url'] as String,
|
||||
key: json['key'] as String,
|
||||
jwt_secret: json['jwt_secret'] as String,
|
||||
collab_table_config: CollabTableConfig.fromJson(
|
||||
json['collab_table_config'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SupabaseDBConfigToJson(SupabaseDBConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'url': instance.url,
|
||||
'key': instance.key,
|
||||
'jwt_secret': instance.jwt_secret,
|
||||
'collab_table_config': instance.collab_table_config,
|
||||
};
|
||||
|
||||
CollabTableConfig _$CollabTableConfigFromJson(Map<String, dynamic> json) =>
|
||||
CollabTableConfig(
|
||||
table_name: json['table_name'] as String,
|
||||
enable: json['enable'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CollabTableConfigToJson(CollabTableConfig instance) =>
|
||||
<String, dynamic>{
|
||||
'table_name': instance.table_name,
|
||||
'enable': instance.enable,
|
||||
};
|
@ -151,3 +151,19 @@ typedef _invoke_log_Dart = void Function(
|
||||
int level,
|
||||
Pointer<ffi.Utf8>,
|
||||
);
|
||||
|
||||
/// C function `set_env`.
|
||||
void set_env(
|
||||
Pointer<ffi.Utf8> data,
|
||||
) {
|
||||
_set_env(data);
|
||||
}
|
||||
|
||||
final _set_env_Dart _set_env =
|
||||
_dart_ffi_lib.lookupFunction<_set_env_C, _set_env_Dart>('set_env');
|
||||
typedef _set_env_C = Void Function(
|
||||
Pointer<ffi.Utf8> data,
|
||||
);
|
||||
typedef _set_env_Dart = void Function(
|
||||
Pointer<ffi.Utf8> data,
|
||||
);
|
||||
|
@ -15,3 +15,5 @@ int32_t set_stream_port(int64_t port);
|
||||
void link_me_please(void);
|
||||
|
||||
void backend_log(int64_t level, const char *data);
|
||||
|
||||
void set_env(const char *data);
|
||||
|
@ -14,3 +14,5 @@ int32_t set_stream_port(int64_t port);
|
||||
void link_me_please(void);
|
||||
|
||||
void backend_log(int64_t level, const char *data);
|
||||
|
||||
void set_env(const char *data);
|
||||
|
@ -18,6 +18,7 @@ dependencies:
|
||||
freezed_annotation:
|
||||
logger: ^1.0.0
|
||||
plugin_platform_interface: ^2.1.3
|
||||
json_annotation: ^4.7.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
@ -25,6 +26,7 @@ dev_dependencies:
|
||||
build_runner:
|
||||
freezed:
|
||||
flutter_lints: ^2.0.1
|
||||
json_serializable: ^6.6.2
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
Reference in New Issue
Block a user