Skip to content

Commit

Permalink
feat: add migration indexes (#573)
Browse files Browse the repository at this point in the history
Co-authored-by: Vasco Santos <[email protected]>
  • Loading branch information
rafaelramalho19 and vasco-santos authored Oct 28, 2021
1 parent b52078f commit c9cd864
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fauna from 'faunadb'

const {
CreateIndex,
Collection,
If,
Index,
Exists,
Not
} = fauna

/**
* Usage:
*
* Match(Index('authtoken_migration_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)
)
31 changes: 31 additions & 0 deletions packages/db/fauna/resources/Migration_indexes/migration_backup.js
Original file line number Diff line number Diff line change
@@ -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)
)
31 changes: 31 additions & 0 deletions packages/db/fauna/resources/Migration_indexes/migration_content.js
Original file line number Diff line number Diff line change
@@ -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)
)
31 changes: 31 additions & 0 deletions packages/db/fauna/resources/Migration_indexes/migration_pin.js
Original file line number Diff line number Diff line change
@@ -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)
)
Original file line number Diff line number Diff line change
@@ -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)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fauna from 'faunadb'

const {
CreateIndex,
Collection,
If,
Index,
Exists,
Not
} = fauna

/**
* Usage:
*
* Match(Index('pinSyncRequest_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)
)
31 changes: 31 additions & 0 deletions packages/db/fauna/resources/Migration_indexes/migration_upload.js
Original file line number Diff line number Diff line change
@@ -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)
)
31 changes: 31 additions & 0 deletions packages/db/fauna/resources/Migration_indexes/migration_user.js
Original file line number Diff line number Diff line change
@@ -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)
)
1 change: 1 addition & 0 deletions packages/db/tools/import-fql-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const main = async () => {
}
await uploadResources('function')
await uploadResources('index')
await uploadResources('migration_indexes')
}

/**
Expand Down

0 comments on commit c9cd864

Please sign in to comment.