Add ts watch support for backend-core + stub out migrations

This commit is contained in:
Rory Powell 2022-05-04 11:22:50 +01:00
parent 606d21b313
commit 23cbd217cd
22 changed files with 87 additions and 13 deletions

View File

@ -8,6 +8,7 @@
"license": "GPL-3.0", "license": "GPL-3.0",
"scripts": { "scripts": {
"build": "rimraf dist/ && tsc -p tsconfig.build.json", "build": "rimraf dist/ && tsc -p tsconfig.build.json",
"dev:builder": "rimraf dist/ && tsc -p tsconfig.build.json --watch",
"test": "jest", "test": "jest",
"test:watch": "jest --watchAll" "test:watch": "jest --watchAll"
}, },

View File

@ -1,6 +1,7 @@
import db from "./db" import db from "./db"
import errors from "./errors" import errors from "./errors"
import * as events from "./events" import * as events from "./events"
import * as migrations from "./migrations"
export = { export = {
init(opts: any = {}) { init(opts: any = {}) {
@ -17,7 +18,7 @@ export = {
cache: require("../cache"), cache: require("../cache"),
auth: require("../auth"), auth: require("../auth"),
constants: require("../constants"), constants: require("../constants"),
migrations: require("../migrations"), migrations,
errors, errors,
...errors.errors, ...errors.errors,
env: require("./environment"), env: require("./environment"),

View File

@ -3,6 +3,7 @@
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"exclude": [ "exclude": [
"node_modules", "node_modules",
"dist/**/*",
"**/*.json", "**/*.json",
"**/*.spec.js", "**/*.spec.js",
"**/*.spec.ts" "**/*.spec.ts"

View File

@ -29,6 +29,7 @@
], ],
"exclude": [ "exclude": [
"node_modules", "node_modules",
"dist/**/*",
"**/*.spec.js", "**/*.spec.js",
// "**/*.spec.ts" // don't exclude spec.ts files for editor support // "**/*.spec.ts" // don't exclude spec.ts files for editor support
] ]

View File

@ -1,6 +1,6 @@
{ {
"watch": ["src", "../backend-core", "../../../budibase-pro/packages/pro"], "watch": ["src", "../backend-core", "../../../budibase-pro/packages/pro"],
"ext": "js,ts,json", "ext": "js,ts,json",
"ignore": ["src/**/*.spec.ts", "src/**/*.spec.js"], "ignore": ["src/**/*.spec.ts", "src/**/*.spec.js", "../backend-core/dist/**/*"],
"exec": "ts-node src/index.ts" "exec": "ts-node src/index.ts"
} }

View File

@ -0,0 +1,4 @@
// TODO: Add migrations to account portal
// ACCOUNT_CREATED = "account:created",
// ACCOUNT_VERIFIED = "account:verified",

View File

@ -0,0 +1,10 @@
export const backfillAppCreated = () => {}
export const backfillAppPublished = () => {}
// APP_CREATED = "app:created",
// APP_PUBLISHED = "app:published",
// Maybe
// APP_TEMPLATE_IMPORTED = "app:template:imported",
// APP_FILE_IMPORTED = "app:file:imported",

View File

@ -0,0 +1,2 @@
// AUTOMATION_CREATED = "automation:created",
// AUTOMATION_STEP_CREATED = "automation:step:created",

View File

@ -0,0 +1 @@
// DATASOURCE_CREATED = "datasource:created",

View File

@ -0,0 +1 @@
// LAYOUT_CREATED = "layout:created",

View File

@ -0,0 +1,3 @@
// QUERY_CREATED = "query:created",
// <!-- maybe -->
// QUERY_IMPORT = "query:import",

View File

@ -0,0 +1,2 @@
// ROLE_CREATED = "role:created",
// ROLE_ASSIGNED = "role:assigned",

View File

@ -0,0 +1 @@
// ROW_IMPORT = "row:import",

View File

@ -0,0 +1 @@
// SCREEN_CREATED = "screen:created",

View File

@ -0,0 +1,3 @@
// TABLE_CREATED = "table:created",
// <!-- maybe -->
// TABLE_DATA_IMPORTED = "table:data:imported",

View File

@ -0,0 +1,3 @@
// VIEW_CREATED = "view:created",
// VIEW_FILTER_CREATED = "view:filter:created",
// VIEW_CALCULATION_CREATED = "view:calculation:created",

View File

@ -0,0 +1,11 @@
import * as app from "./app/app"
/**
* Date:
* May 2022
*
* Description:
* Backfill app events.
*/
export const run = async (db: any) => {}

View File

@ -0,0 +1,11 @@
import * as syncPublishedApps from "../usageQuotas/syncPublishedApps"
/**
* Date:
* May 2022
*
* Description:
* Backfill global events.
*/
export const run = async (db: any) => {}

View File

@ -0,0 +1,7 @@
// EMAIL_SMTP_CREATED = "email:smtp:created",
// AUTH_SSO_CREATED = "auth:sso:created",
// AUTH_SSO_ACTIVATED = "auth:sso:activated",
// AUTH_SSO_DEACTIVATED = "auth:sso:deactivated",
// ORG_NAME_UPDATED = "org:info:name:updated",
// ORG_LOGO_UPDATED = "org:info:logo:updated",
// ORG_PLATFORM_URL_UPDATED = "org:platformurl:updated",

View File

@ -0,0 +1,3 @@
// USER_CREATED = "user:created",
// USER_PERMISSION_ADMIN_ASSIGNED = "user:admin:assigned",
// USER_PERMISSION_BUILDER_ASSIGNED = "user:builder:assigned",

View File

@ -1,7 +1,4 @@
const { import { migrations } from "@budibase/backend-core"
MIGRATION_TYPES,
runMigrations,
} = require("@budibase/backend-core/migrations")
// migration functions // migration functions
import * as userEmailViewCasing from "./functions/userEmailViewCasing" import * as userEmailViewCasing from "./functions/userEmailViewCasing"
@ -35,33 +32,43 @@ export interface MigrationOptions {
export const MIGRATIONS: Migration[] = [ export const MIGRATIONS: Migration[] = [
{ {
type: MIGRATION_TYPES.GLOBAL, type: migrations.MIGRATION_TYPES.GLOBAL,
name: "user_email_view_casing", name: "user_email_view_casing",
fn: userEmailViewCasing.run, fn: userEmailViewCasing.run,
}, },
{ {
type: MIGRATION_TYPES.GLOBAL, type: migrations.MIGRATION_TYPES.GLOBAL,
name: "quotas_1", name: "quotas_1",
fn: quota1.run, fn: quota1.run,
}, },
{ {
type: MIGRATION_TYPES.APP, type: migrations.MIGRATION_TYPES.APP,
name: "app_urls", name: "app_urls",
opts: { all: true }, opts: { all: true },
fn: appUrls.run, fn: appUrls.run,
}, },
{ {
type: MIGRATION_TYPES.GLOBAL, type: migrations.MIGRATION_TYPES.GLOBAL,
name: "developer_quota", name: "developer_quota",
fn: developerQuota.run, fn: developerQuota.run,
}, },
{ {
type: MIGRATION_TYPES.GLOBAL, type: migrations.MIGRATION_TYPES.GLOBAL,
name: "published_apps_quota", name: "published_apps_quota",
fn: publishedAppsQuota.run, fn: publishedAppsQuota.run,
}, },
{
type: migrations.MIGRATION_TYPES.GLOBAL,
name: "event_backfill",
fn: publishedAppsQuota.run,
},
{
type: migrations.MIGRATION_TYPES.APP,
name: "event_app_backfill",
fn: publishedAppsQuota.run,
},
] ]
export const migrate = async (options?: MigrationOptions) => { export const migrate = async (options?: MigrationOptions) => {
await runMigrations(MIGRATIONS, options) await migrations.runMigrations(MIGRATIONS, options)
} }

View File

@ -1,6 +1,6 @@
{ {
"watch": ["src", "../backend-core", "../../../budibase-pro/packages/pro"], "watch": ["src", "../backend-core", "../../../budibase-pro/packages/pro"],
"ext": "js,ts,json", "ext": "js,ts,json",
"ignore": ["src/**/*.spec.ts", "src/**/*.spec.js"], "ignore": ["src/**/*.spec.ts", "src/**/*.spec.js", "../backend-core/dist/**/*"],
"exec": "ts-node src/index.ts" "exec": "ts-node src/index.ts"
} }