Initial commit
This commit is contained in:
94
pocketbase/pb_migrations/0_setup.js
Normal file
94
pocketbase/pb_migrations/0_setup.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
// Set basic settings
|
||||
let settings = app.settings()
|
||||
|
||||
const appUrl = $os.getenv('POCKETBASE_URL') || 'http://127.0.0.1:8090'
|
||||
const appName = $os.getenv('APP_NAME') || 'PocketBase'
|
||||
|
||||
const smtpHost = $os.getenv('SMTP_HOST') || 'mailpit'
|
||||
const smtpPort = Number($os.getenv('SMTP_PORT') || 1025)
|
||||
|
||||
unmarshal({
|
||||
meta: {
|
||||
appName,
|
||||
appUrl
|
||||
},
|
||||
smtp: {
|
||||
enabled: true,
|
||||
host: smtpHost,
|
||||
port: smtpPort
|
||||
}
|
||||
}, settings)
|
||||
|
||||
app.save(settings)
|
||||
|
||||
// Enable auth methods
|
||||
const collection = app.findCollectionByNameOrId('_pb_users_auth_')
|
||||
|
||||
const googleClientId = $os.getenv('AUTH_GOOGLE_CLIENT_ID')
|
||||
const googleClientSecret = $os.getenv('AUTH_GOOGLE_CLIENT_SECRET')
|
||||
|
||||
const appleClientId = $os.getenv('AUTH_APPLE_CLIENT_ID')
|
||||
const appleClientSecret = $os.getenv('AUTH_APPLE_CLIENT_SECRET')
|
||||
|
||||
const providers = []
|
||||
if (googleClientId?.length && googleClientSecret?.length) {
|
||||
providers.push({
|
||||
name: 'google',
|
||||
clientId: googleClientId,
|
||||
clientSecret: googleClientSecret
|
||||
})
|
||||
}
|
||||
if (appleClientId?.length && appleClientSecret?.length) {
|
||||
providers.push({
|
||||
name: 'apple',
|
||||
clientId: appleClientId,
|
||||
clientSecret: appleClientSecret
|
||||
})
|
||||
}
|
||||
|
||||
unmarshal({
|
||||
oauth2: {
|
||||
enabled: true,
|
||||
providers
|
||||
},
|
||||
otp: {
|
||||
duration: 300,
|
||||
enabled: true,
|
||||
length: 6
|
||||
}
|
||||
}, collection)
|
||||
app.save(collection)
|
||||
|
||||
// Create admin user if it doesn't exist
|
||||
const email = $os.getenv('SUPERUSER_EMAIL')
|
||||
const password = $os.getenv('SUPERUSER_PW')
|
||||
|
||||
if (email?.length && password?.length) {
|
||||
const existingUser = app.findFirstRecordByData('_superusers', 'email', email)
|
||||
|
||||
if (!existingUser) {
|
||||
let superusers = app.findCollectionByNameOrId('_superusers')
|
||||
let record = new Record(superusers)
|
||||
record.set('email', email)
|
||||
record.set('password', password)
|
||||
app.save(record)
|
||||
}
|
||||
}
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId('_pb_users_auth_')
|
||||
|
||||
unmarshal({
|
||||
oauth2: {
|
||||
enabled: false
|
||||
},
|
||||
otp: {
|
||||
duration: 180,
|
||||
enabled: false,
|
||||
length: 8
|
||||
}
|
||||
}, collection)
|
||||
|
||||
app.save(collection)
|
||||
})
|
||||
29
pocketbase/pb_migrations/1_users_language.js
Normal file
29
pocketbase/pb_migrations/1_users_language.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
const collection = app.findCollectionByNameOrId('_pb_users_auth_')
|
||||
|
||||
// add field
|
||||
collection.fields.addAt(8, new Field({
|
||||
hidden: false,
|
||||
id: 'select3571151285',
|
||||
maxSelect: 1,
|
||||
name: 'language',
|
||||
presentable: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'select',
|
||||
values: [
|
||||
'de',
|
||||
'en'
|
||||
]
|
||||
}))
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId('_pb_users_auth_')
|
||||
|
||||
// remove field
|
||||
collection.fields.removeById('select3571151285')
|
||||
|
||||
return app.save(collection)
|
||||
})
|
||||
110
pocketbase/pb_migrations/2_notifications.js
Normal file
110
pocketbase/pb_migrations/2_notifications.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
if (app.hasTable('notifications')) {
|
||||
return
|
||||
}
|
||||
const collection = new Collection({
|
||||
fields: [
|
||||
{
|
||||
autogeneratePattern: '[a-z0-9]{15}',
|
||||
hidden: false,
|
||||
id: 'text3208210256',
|
||||
max: 15,
|
||||
min: 15,
|
||||
name: 'id',
|
||||
pattern: '^[a-z0-9]+$',
|
||||
presentable: false,
|
||||
primaryKey: true,
|
||||
required: true,
|
||||
system: true,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
cascadeDelete: false,
|
||||
collectionId: '_pb_users_auth_',
|
||||
hidden: false,
|
||||
id: 'relation1689669068',
|
||||
maxSelect: 1,
|
||||
minSelect: 0,
|
||||
name: 'userId',
|
||||
presentable: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'relation'
|
||||
},
|
||||
{
|
||||
autogeneratePattern: '',
|
||||
hidden: false,
|
||||
id: 'text724990059',
|
||||
max: 0,
|
||||
min: 0,
|
||||
name: 'title',
|
||||
pattern: '',
|
||||
presentable: false,
|
||||
primaryKey: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
autogeneratePattern: '',
|
||||
hidden: false,
|
||||
id: 'text3685223346',
|
||||
max: 0,
|
||||
min: 0,
|
||||
name: 'body',
|
||||
pattern: '',
|
||||
presentable: false,
|
||||
primaryKey: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'bool963269739',
|
||||
name: 'isRead',
|
||||
presentable: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'bool'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'autodate2990389176',
|
||||
name: 'created',
|
||||
onCreate: true,
|
||||
onUpdate: false,
|
||||
presentable: false,
|
||||
system: false,
|
||||
type: 'autodate'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'autodate3332085495',
|
||||
name: 'updated',
|
||||
onCreate: true,
|
||||
onUpdate: true,
|
||||
presentable: false,
|
||||
system: false,
|
||||
type: 'autodate'
|
||||
}
|
||||
],
|
||||
id: 'pbc_2301922722',
|
||||
indexes: [],
|
||||
listRule: 'userId = @request.auth.id',
|
||||
name: 'notifications',
|
||||
system: false,
|
||||
type: 'base',
|
||||
createRule: null,
|
||||
deleteRule: null,
|
||||
updateRule: 'userId = @request.auth.id',
|
||||
viewRule: 'userId = @request.auth.id'
|
||||
})
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId('pbc_2301922722')
|
||||
|
||||
return app.delete(collection)
|
||||
})
|
||||
87
pocketbase/pb_migrations/3_fcm_tokens.js
Normal file
87
pocketbase/pb_migrations/3_fcm_tokens.js
Normal file
@@ -0,0 +1,87 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
if (app.hasTable('fcm_tokens')) {
|
||||
return
|
||||
}
|
||||
const collection = new Collection({
|
||||
fields: [
|
||||
{
|
||||
autogeneratePattern: '[a-z0-9]{15}',
|
||||
hidden: false,
|
||||
id: 'text3208210256',
|
||||
max: 15,
|
||||
min: 15,
|
||||
name: 'id',
|
||||
pattern: '^[a-z0-9]+$',
|
||||
presentable: false,
|
||||
primaryKey: true,
|
||||
required: true,
|
||||
system: true,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
cascadeDelete: false,
|
||||
collectionId: '_pb_users_auth_',
|
||||
hidden: false,
|
||||
id: 'relation1689669068',
|
||||
maxSelect: 1,
|
||||
minSelect: 0,
|
||||
name: 'userId',
|
||||
presentable: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'relation'
|
||||
},
|
||||
{
|
||||
autogeneratePattern: '',
|
||||
hidden: false,
|
||||
id: 'text1597481275',
|
||||
max: 0,
|
||||
min: 0,
|
||||
name: 'token',
|
||||
pattern: '',
|
||||
presentable: false,
|
||||
primaryKey: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'autodate2990389176',
|
||||
name: 'created',
|
||||
onCreate: true,
|
||||
onUpdate: false,
|
||||
presentable: false,
|
||||
system: false,
|
||||
type: 'autodate'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'autodate3332085495',
|
||||
name: 'updated',
|
||||
onCreate: true,
|
||||
onUpdate: true,
|
||||
presentable: false,
|
||||
system: false,
|
||||
type: 'autodate'
|
||||
}
|
||||
],
|
||||
id: 'pbc_566627753',
|
||||
indexes: [],
|
||||
listRule: 'userId = @request.auth.id',
|
||||
name: 'fcm_tokens',
|
||||
system: false,
|
||||
type: 'base',
|
||||
deleteRule: null,
|
||||
updateRule: null,
|
||||
viewRule: 'userId = @request.auth.id',
|
||||
createRule: 'userId = @request.auth.id'
|
||||
})
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId('pbc_566627753')
|
||||
|
||||
return app.delete(collection)
|
||||
})
|
||||
85
pocketbase/pb_migrations/4_counters.js
Normal file
85
pocketbase/pb_migrations/4_counters.js
Normal file
@@ -0,0 +1,85 @@
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
migrate((app) => {
|
||||
if (app.hasTable('counters')) {
|
||||
return
|
||||
}
|
||||
const collection = new Collection({
|
||||
fields: [
|
||||
{
|
||||
autogeneratePattern: '[a-z0-9]{15}',
|
||||
hidden: false,
|
||||
id: 'text3208210256',
|
||||
max: 15,
|
||||
min: 15,
|
||||
name: 'id',
|
||||
pattern: '^[a-z0-9]+$',
|
||||
presentable: false,
|
||||
primaryKey: true,
|
||||
required: true,
|
||||
system: true,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
cascadeDelete: false,
|
||||
collectionId: '_pb_users_auth_',
|
||||
hidden: false,
|
||||
id: 'relation1689669068',
|
||||
maxSelect: 1,
|
||||
minSelect: 0,
|
||||
name: 'userId',
|
||||
presentable: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'relation'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'number2245608546',
|
||||
max: null,
|
||||
min: null,
|
||||
name: 'count',
|
||||
onlyInt: false,
|
||||
presentable: false,
|
||||
required: false,
|
||||
system: false,
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'autodate2990389176',
|
||||
name: 'created',
|
||||
onCreate: true,
|
||||
onUpdate: false,
|
||||
presentable: false,
|
||||
system: false,
|
||||
type: 'autodate'
|
||||
},
|
||||
{
|
||||
hidden: false,
|
||||
id: 'autodate3332085495',
|
||||
name: 'updated',
|
||||
onCreate: true,
|
||||
onUpdate: true,
|
||||
presentable: false,
|
||||
system: false,
|
||||
type: 'autodate'
|
||||
}
|
||||
],
|
||||
id: 'pbc_90131592',
|
||||
indexes: [],
|
||||
listRule: 'userId = @request.auth.id',
|
||||
name: 'counters',
|
||||
system: false,
|
||||
type: 'base',
|
||||
deleteRule: 'userId = @request.auth.id',
|
||||
updateRule: 'userId = @request.auth.id',
|
||||
viewRule: 'userId = @request.auth.id',
|
||||
createRule: 'userId = @request.auth.id'
|
||||
})
|
||||
|
||||
return app.save(collection)
|
||||
}, (app) => {
|
||||
const collection = app.findCollectionByNameOrId('pbc_90131592')
|
||||
|
||||
return app.delete(collection)
|
||||
})
|
||||
Reference in New Issue
Block a user