WIP
This commit is contained in:
parent
ff859a5516
commit
0863e92e00
|
@ -0,0 +1 @@
|
||||||
|
export 'license_constants.dart';
|
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
const String tableLicense = 'license';
|
||||||
|
|
||||||
|
String get createLicenseTable => '''
|
||||||
|
CREATE TABLE IF NOT EXISTS $tableLicense (
|
||||||
|
key TEXT UNIQUE,
|
||||||
|
display TEXT,
|
||||||
|
expirationDate TEXT,
|
||||||
|
startDate TEXT,
|
||||||
|
quantity TEXT
|
||||||
|
);
|
||||||
|
''';
|
||||||
|
|
||||||
|
String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;';
|
||||||
|
|
||||||
|
String get updatePetsHistoryTrigger => '''
|
||||||
|
CREATE TRIGGER update_fre_hub_pets_history
|
||||||
|
AFTER INSERT ON $tableLicense
|
||||||
|
WHEN NEW.key = 'FRE-HUB-PETS'
|
||||||
|
BEGIN
|
||||||
|
INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity)
|
||||||
|
VALUES ('FRE-HUB-PETS-HISTORY', NEW.display, NEW.expirationDate, NEW.startDate, NEW.quantity);
|
||||||
|
END;
|
||||||
|
''';
|
||||||
|
|
||||||
|
String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;';
|
||||||
|
|
||||||
|
String get updateDisplayTrigger => '''
|
||||||
|
CREATE TRIGGER update_display_trigger
|
||||||
|
AFTER UPDATE ON $tableLicense
|
||||||
|
WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS')
|
||||||
|
BEGIN
|
||||||
|
UPDATE $tableLicense
|
||||||
|
SET display = CASE
|
||||||
|
WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') AND display = 'VISIVEL') > 0
|
||||||
|
THEN 'VISIVEL'
|
||||||
|
ELSE 'INVISIVEL'
|
||||||
|
END
|
||||||
|
WHERE key = 'FRE-HUB-ABOUT-PROPERTY';
|
||||||
|
END;
|
||||||
|
''';
|
||||||
|
|
||||||
|
String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;';
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:hub/shared/components/molecules/modules/index.dart';
|
||||||
import 'package:hub/shared/helpers/database/database_helper.dart';
|
import 'package:hub/shared/helpers/database/database_helper.dart';
|
||||||
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
import 'package:hub/shared/helpers/storage/base_storage.dart';
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
@ -19,48 +20,6 @@ class LicenseLocalDataSourceImpl implements LicenseLocalDataSource {
|
||||||
factory LicenseLocalDataSourceImpl() => _instance;
|
factory LicenseLocalDataSourceImpl() => _instance;
|
||||||
LicenseLocalDataSourceImpl._internal();
|
LicenseLocalDataSourceImpl._internal();
|
||||||
|
|
||||||
static const String tableLicense = 'license';
|
|
||||||
|
|
||||||
static String get createLicenseTable => '''
|
|
||||||
CREATE TABLE IF NOT EXISTS $tableLicense (
|
|
||||||
key TEXT UNIQUE,
|
|
||||||
display TEXT,
|
|
||||||
expirationDate TEXT,
|
|
||||||
startDate TEXT,
|
|
||||||
quantity TEXT
|
|
||||||
);
|
|
||||||
''';
|
|
||||||
|
|
||||||
static String get deleteLicenseTable => 'DROP TABLE IF EXISTS $tableLicense;';
|
|
||||||
|
|
||||||
static String get updatePetsHistoryTrigger => '''
|
|
||||||
CREATE TRIGGER update_fre_hub_pets_history
|
|
||||||
AFTER INSERT ON $tableLicense
|
|
||||||
WHEN NEW.key = 'FRE-HUB-PETS'
|
|
||||||
BEGIN
|
|
||||||
INSERT OR REPLACE INTO $tableLicense (key, display, expirationDate, startDate, quantity)
|
|
||||||
VALUES ('FRE-HUB-PETS-HISTORY', NEW.display, NEW.expirationDate, NEW.startDate, NEW.quantity);
|
|
||||||
END;
|
|
||||||
''';
|
|
||||||
|
|
||||||
static String get dropPetsHistoryTrigger => 'DROP TRIGGER IF EXISTS update_fre_hub_pets_history;';
|
|
||||||
|
|
||||||
static String get updateDisplayTrigger => '''
|
|
||||||
CREATE TRIGGER update_display_trigger
|
|
||||||
AFTER UPDATE ON $tableLicense
|
|
||||||
WHEN NEW.key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS')
|
|
||||||
BEGIN
|
|
||||||
UPDATE $tableLicense
|
|
||||||
SET display = CASE
|
|
||||||
WHEN (SELECT COUNT(*) FROM $tableLicense WHERE key IN ('FRE-HUB-OPENED-VISITS', 'FRE-HUB-VEHICLES', 'FRE-HUB-RESIDENTS', 'FRE-HUB-PETS') AND display = 'VISIVEL') > 0
|
|
||||||
THEN 'VISIVEL'
|
|
||||||
ELSE 'INVISIVEL'
|
|
||||||
END
|
|
||||||
WHERE key = 'FRE-HUB-ABOUT-PROPERTY';
|
|
||||||
END;
|
|
||||||
''';
|
|
||||||
|
|
||||||
static String get dropDisplayTrigger => 'DROP TRIGGER IF EXISTS update_display_trigger;';
|
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await DatabaseStorage.instance.init();
|
await DatabaseStorage.instance.init();
|
||||||
|
|
|
@ -169,8 +169,7 @@ class License {
|
||||||
startDate: '',
|
startDate: '',
|
||||||
quantity: 0,
|
quantity: 0,
|
||||||
),
|
),
|
||||||
]
|
]);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export 'data/index.dart';
|
export 'data/index.dart';
|
||||||
export 'domain/index.dart';
|
export 'domain/index.dart';
|
||||||
export 'presentation/index.dart';
|
export 'presentation/index.dart';
|
||||||
|
export 'constants/index.dart';
|
|
@ -0,0 +1 @@
|
||||||
|
export 'keychain_constants.dart';
|
|
@ -0,0 +1,13 @@
|
||||||
|
const String tableKeychain = 'keychain';
|
||||||
|
|
||||||
|
String get createKeychainTable => '''
|
||||||
|
CREATE TABLE $tableKeychain (
|
||||||
|
key TEXT UNIQUE,
|
||||||
|
value TEXT,
|
||||||
|
type TEXT,
|
||||||
|
updateAt TEXT,
|
||||||
|
resolvedAt TEXT,
|
||||||
|
createdAt TEXT
|
||||||
|
);
|
||||||
|
''';
|
||||||
|
String get deleteKeychainTable => 'DROP TABLE IF EXISTS $tableKeychain;';
|
|
@ -1,5 +1,5 @@
|
||||||
import 'package:hub/shared/components/molecules/modules/data/data_sources/license_local_data_source.dart';
|
import 'package:hub/shared/components/molecules/modules/index.dart';
|
||||||
import 'package:hub/shared/components/molecules/modules/data/repositories/license_repository_impl.dart';
|
import 'package:hub/shared/constants/index.dart';
|
||||||
import 'package:hub/shared/helpers/storage/keychain_storage.dart';
|
import 'package:hub/shared/helpers/storage/keychain_storage.dart';
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
|
@ -38,33 +38,33 @@ class DatabaseStorage {
|
||||||
|
|
||||||
Future<void> _onCreate(Database database, int version) async {
|
Future<void> _onCreate(Database database, int version) async {
|
||||||
log('Creating database...');
|
log('Creating database...');
|
||||||
await database.execute(KeychainHelper.createKeychainTable);
|
await database.execute(createKeychainTable);
|
||||||
await database.execute(LicenseLocalDataSourceImpl.createLicenseTable);
|
await database.execute(createLicenseTable);
|
||||||
if (version >= 2) {
|
if (version >= 2) {
|
||||||
await database.execute(LicenseLocalDataSourceImpl.updatePetsHistoryTrigger);
|
await database.execute(updatePetsHistoryTrigger);
|
||||||
}
|
}
|
||||||
if (version >= 3) {
|
if (version >= 3) {
|
||||||
await database.execute(LicenseLocalDataSourceImpl.updateDisplayTrigger);
|
await database.execute(updateDisplayTrigger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onUpgrade(Database database, int oldVersion, int newVersion) async {
|
Future<void> _onUpgrade(Database database, int oldVersion, int newVersion) async {
|
||||||
log('Upgrading database from version $oldVersion to $newVersion...');
|
log('Upgrading database from version $oldVersion to $newVersion...');
|
||||||
if (oldVersion < 2 && newVersion >= 2) {
|
if (oldVersion < 2 && newVersion >= 2) {
|
||||||
await database.execute(LicenseLocalDataSourceImpl.updatePetsHistoryTrigger);
|
await database.execute(updatePetsHistoryTrigger);
|
||||||
}
|
}
|
||||||
if (oldVersion < 3 && newVersion >= 3) {
|
if (oldVersion < 3 && newVersion >= 3) {
|
||||||
await database.execute(LicenseLocalDataSourceImpl.updateDisplayTrigger);
|
await database.execute(updateDisplayTrigger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onDowngrade(Database database, int oldVersion, int newVersion) async {
|
Future<void> _onDowngrade(Database database, int oldVersion, int newVersion) async {
|
||||||
log('Downgrading database from version $oldVersion to $newVersion...');
|
log('Downgrading database from version $oldVersion to $newVersion...');
|
||||||
if (oldVersion >= 3 && newVersion < 3) {
|
if (oldVersion >= 3 && newVersion < 3) {
|
||||||
await database.execute(LicenseLocalDataSourceImpl.dropDisplayTrigger);
|
await database.execute(dropDisplayTrigger);
|
||||||
}
|
}
|
||||||
if (oldVersion >= 2 && newVersion < 2) {
|
if (oldVersion >= 2 && newVersion < 2) {
|
||||||
await database.execute(LicenseLocalDataSourceImpl.dropPetsHistoryTrigger);
|
await database.execute(dropPetsHistoryTrigger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,10 @@ class KeychainHelper implements BaseStorage {
|
||||||
|
|
||||||
static final KeychainHelper instance = KeychainHelper._();
|
static final KeychainHelper instance = KeychainHelper._();
|
||||||
|
|
||||||
static const String tableKeychain = 'keychain';
|
|
||||||
bool _isInitialized = false;
|
bool _isInitialized = false;
|
||||||
|
|
||||||
|
static const String tableKeychain = 'keychain';
|
||||||
|
|
||||||
static String get createKeychainTable => '''
|
static String get createKeychainTable => '''
|
||||||
CREATE TABLE $tableKeychain (
|
CREATE TABLE $tableKeychain (
|
||||||
key TEXT UNIQUE,
|
key TEXT UNIQUE,
|
||||||
|
|
Loading…
Reference in New Issue