made scripts contain only single command
This commit is contained in:
parent
cf657d4db3
commit
5c497c7789
2 changed files with 44 additions and 33 deletions
|
@ -25,11 +25,10 @@ class CollectionsDB {
|
|||
static final columnSharees = 'sharees';
|
||||
static final columnUpdationTime = 'updation_time';
|
||||
|
||||
static final intitialScript = [onCreate(collectionsTable)];
|
||||
static final intitialScript = [...onCreate(collectionsTable)];
|
||||
static final migrationScripts = [
|
||||
alterNameToAllowNULL(),
|
||||
addEncryptedName(),
|
||||
addnameDecryptionNonce(),
|
||||
...alterNameToAllowNULL(),
|
||||
...addEncryptedName(),
|
||||
];
|
||||
|
||||
final dbConfig = MigrationConfig(
|
||||
|
@ -51,8 +50,9 @@ class CollectionsDB {
|
|||
return await openDatabaseWithMigration(path, dbConfig);
|
||||
}
|
||||
|
||||
static String onCreate(String tableName) {
|
||||
return '''
|
||||
static List<String> onCreate(String tableName) {
|
||||
return [
|
||||
'''
|
||||
CREATE TABLE $tableName (
|
||||
$columnID INTEGER PRIMARY KEY NOT NULL,
|
||||
$columnOwner TEXT NOT NULL,
|
||||
|
@ -65,33 +65,38 @@ class CollectionsDB {
|
|||
$columnSharees TEXT,
|
||||
$columnUpdationTime TEXT NOT NULL
|
||||
);
|
||||
''';
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
static String alterNameToAllowNULL() {
|
||||
return onCreate(collectionsTableCopy) +
|
||||
'''
|
||||
static List<String> alterNameToAllowNULL() {
|
||||
return [
|
||||
...onCreate(collectionsTableCopy),
|
||||
'''
|
||||
INSERT INTO $collectionsTableCopy
|
||||
SELECT *
|
||||
FROM $collectionsTable;
|
||||
''',
|
||||
'''
|
||||
DROP TABLE $collectionsTable;
|
||||
|
||||
''',
|
||||
'''
|
||||
ALTER TABLE $collectionsTableCopy
|
||||
RENAME TO $collectionsTable;
|
||||
''';
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
static String addEncryptedName() {
|
||||
return '''
|
||||
static List<String> addEncryptedName() {
|
||||
return [
|
||||
'''
|
||||
ALTER TABLE $collectionsTable
|
||||
ADD COLUMN $columnEncryptedName TEXT;
|
||||
''';
|
||||
}
|
||||
|
||||
static String addnameDecryptionNonce() {
|
||||
return '''ALTER TABLE $collectionsTable
|
||||
''',
|
||||
'''ALTER TABLE $collectionsTable
|
||||
ADD COLUMN $columnNameDecryptionNonce TEXT;
|
||||
''';
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
Future<List<dynamic>> insert(List<Collection> collections) async {
|
||||
|
|
|
@ -38,8 +38,8 @@ class FilesDB {
|
|||
static final columnThumbnailDecryptionHeader = 'thumbnail_decryption_header';
|
||||
static final columnMetadataDecryptionHeader = 'metadata_decryption_header';
|
||||
|
||||
static final intitialScript = [onCreate(table)];
|
||||
static final migrationScripts = [alterDeviceFolderToAllowNULL()];
|
||||
static final intitialScript = [...onCreate(table)];
|
||||
static final migrationScripts = [...alterDeviceFolderToAllowNULL()];
|
||||
|
||||
final dbConfig = MigrationConfig(
|
||||
initializationScript: intitialScript, migrationScripts: migrationScripts);
|
||||
|
@ -64,8 +64,9 @@ class FilesDB {
|
|||
}
|
||||
|
||||
// SQL code to create the database table
|
||||
static String onCreate(String tablename) {
|
||||
return '''
|
||||
static List<String> onCreate(String tablename) {
|
||||
return [
|
||||
'''
|
||||
CREATE TABLE $tablename (
|
||||
$columnGeneratedID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
$columnLocalID TEXT,
|
||||
|
@ -88,27 +89,32 @@ class FilesDB {
|
|||
$columnCreationTime TEXT NOT NULL,
|
||||
$columnUpdationTime TEXT,
|
||||
UNIQUE($columnUploadedFileID, $columnCollectionID)
|
||||
);
|
||||
|
||||
);''',
|
||||
'''
|
||||
CREATE INDEX collection_id_index ON $table($columnCollectionID);
|
||||
CREATE INDEX device_folder_index ON $table($columnDeviceFolder);
|
||||
CREATE INDEX creation_time_index ON $table($columnCreationTime);
|
||||
CREATE INDEX updation_time_index ON $table($columnUpdationTime);
|
||||
''';
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
static String alterDeviceFolderToAllowNULL() {
|
||||
return onCreate(tableCopy) +
|
||||
'''
|
||||
static List<String> alterDeviceFolderToAllowNULL() {
|
||||
return [
|
||||
...onCreate(tableCopy),
|
||||
'''
|
||||
INSERT INTO $tableCopy
|
||||
SELECT *
|
||||
FROM $table;
|
||||
|
||||
''',
|
||||
'''
|
||||
DROP TABLE $table;
|
||||
|
||||
''',
|
||||
'''
|
||||
ALTER TABLE $tableCopy
|
||||
RENAME TO $table;
|
||||
''';
|
||||
'''
|
||||
];
|
||||
}
|
||||
|
||||
Future<int> insert(File file) async {
|
||||
|
|
Loading…
Add table
Reference in a new issue