From 30715a3a1927777a91ea6bb98e9f0f1406c3d616 Mon Sep 17 00:00:00 2001 From: Rafael Ramalho Date: Thu, 28 Oct 2021 17:13:44 +0100 Subject: [PATCH 1/2] chore: add migration indexes --- .../Migration_indexes/migration_authToken.js | 31 +++++++++++++++++++ .../Migration_indexes/migration_backup.js | 31 +++++++++++++++++++ .../Migration_indexes/migration_content.js | 31 +++++++++++++++++++ .../Migration_indexes/migration_pin.js | 31 +++++++++++++++++++ .../Migration_indexes/migration_pinRequest.js | 31 +++++++++++++++++++ .../migration_pinSyncRequest.js | 31 +++++++++++++++++++ .../Migration_indexes/migration_upload.js | 31 +++++++++++++++++++ .../Migration_indexes/migration_user.js | 31 +++++++++++++++++++ packages/db/tools/import-fql-resources.js | 1 + 9 files changed, 249 insertions(+) create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_authToken.js create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_backup.js create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_content.js create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_pin.js create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_pinRequest.js create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_upload.js create mode 100644 packages/db/fauna/resources/Migration_indexes/migration_user.js diff --git a/packages/db/fauna/resources/Migration_indexes/migration_authToken.js b/packages/db/fauna/resources/Migration_indexes/migration_authToken.js new file mode 100644 index 0000000000..cd80cc0400 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_authToken.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('authtoken_filter_by_timestamp')) + */ +const index = { + name: 'authtoken_migration_timestamp', + source: Collection('AuthToken'), + values: [ + { field: ['data', 'updated'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_backup.js b/packages/db/fauna/resources/Migration_indexes/migration_backup.js new file mode 100644 index 0000000000..54b8bc96c4 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_backup.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('backup_migration_timestamp')) + */ +const index = { + name: 'backup_migration_timestamp', + source: Collection('Backup'), + values: [ + { field: ['data', 'created'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_content.js b/packages/db/fauna/resources/Migration_indexes/migration_content.js new file mode 100644 index 0000000000..aa6d24e9c1 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_content.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('content_migration_timestamp')) + */ +const index = { + name: 'content_migration_timestamp', + source: Collection('Content'), + values: [ + { field: ['data', 'created'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_pin.js b/packages/db/fauna/resources/Migration_indexes/migration_pin.js new file mode 100644 index 0000000000..56a7031408 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_pin.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('pin_migration_timestamp')) + */ +const index = { + name: 'pin_migration_timestamp', + source: Collection('Pin'), + values: [ + { field: ['data', 'updated'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_pinRequest.js b/packages/db/fauna/resources/Migration_indexes/migration_pinRequest.js new file mode 100644 index 0000000000..406d30e7b2 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_pinRequest.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('pinrequest_migration_timestamp')) + */ +const index = { + name: 'pinrequest_migration_timestamp', + source: Collection('PinRequest'), + values: [ + { field: ['data', 'updated'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js b/packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js new file mode 100644 index 0000000000..222a740a57 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('pinSync_migration_timestamp')) + */ +const index = { + name: 'pinSyncRequest_migration_timestamp', + source: Collection('PinSyncRequest'), + values: [ + { field: ['data', 'created'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_upload.js b/packages/db/fauna/resources/Migration_indexes/migration_upload.js new file mode 100644 index 0000000000..de563b1262 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_upload.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('upload_migration_timestamp')) + */ +const index = { + name: 'upload_migration_timestamp', + source: Collection('Upload'), + values: [ + { field: ['data', 'updated'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_user.js b/packages/db/fauna/resources/Migration_indexes/migration_user.js new file mode 100644 index 0000000000..22c2aee7e3 --- /dev/null +++ b/packages/db/fauna/resources/Migration_indexes/migration_user.js @@ -0,0 +1,31 @@ +import fauna from 'faunadb' + +const { + CreateIndex, + Collection, + If, + Index, + Exists, + Not +} = fauna + +/** + * Usage: + * + * Match(Index('user_migration_timestamp')) + */ +const index = { + name: 'user_migration_timestamp', + source: Collection('User'), + values: [ + { field: ['data', 'created'] }, + { field: 'ref' } + ] +} + +// indexes cannot be updated +export default If( + Not(Exists(Index(index.name))), + CreateIndex(index), + Index(index.name) +) diff --git a/packages/db/tools/import-fql-resources.js b/packages/db/tools/import-fql-resources.js index 779a2b3dbd..debb23a4be 100644 --- a/packages/db/tools/import-fql-resources.js +++ b/packages/db/tools/import-fql-resources.js @@ -11,6 +11,7 @@ const main = async () => { } await uploadResources('function') await uploadResources('index') + await uploadResources('migration_indexes') } /** From bf561166a7b78328c648ab6eb1aa0db2cffee839 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 28 Oct 2021 21:40:28 +0200 Subject: [PATCH 2/2] chore: apply suggestions from code review --- .../db/fauna/resources/Migration_indexes/migration_authToken.js | 2 +- .../resources/Migration_indexes/migration_pinSyncRequest.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/db/fauna/resources/Migration_indexes/migration_authToken.js b/packages/db/fauna/resources/Migration_indexes/migration_authToken.js index cd80cc0400..0989b702aa 100644 --- a/packages/db/fauna/resources/Migration_indexes/migration_authToken.js +++ b/packages/db/fauna/resources/Migration_indexes/migration_authToken.js @@ -12,7 +12,7 @@ const { /** * Usage: * - * Match(Index('authtoken_filter_by_timestamp')) + * Match(Index('authtoken_migration_timestamp')) */ const index = { name: 'authtoken_migration_timestamp', diff --git a/packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js b/packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js index 222a740a57..f22cda42ed 100644 --- a/packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js +++ b/packages/db/fauna/resources/Migration_indexes/migration_pinSyncRequest.js @@ -12,7 +12,7 @@ const { /** * Usage: * - * Match(Index('pinSync_migration_timestamp')) + * Match(Index('pinSyncRequest_migration_timestamp')) */ const index = { name: 'pinSyncRequest_migration_timestamp',