@budibase/server 2.6.19-alpha.29 → 2.6.19-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.6.19-alpha.29",
4
+ "version": "2.6.19-alpha.30",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -46,12 +46,12 @@
46
46
  "license": "GPL-3.0",
47
47
  "dependencies": {
48
48
  "@apidevtools/swagger-parser": "10.0.3",
49
- "@budibase/backend-core": "2.6.19-alpha.29",
50
- "@budibase/client": "2.6.19-alpha.29",
51
- "@budibase/pro": "2.6.19-alpha.29",
52
- "@budibase/shared-core": "2.6.19-alpha.29",
53
- "@budibase/string-templates": "2.6.19-alpha.29",
54
- "@budibase/types": "2.6.19-alpha.29",
49
+ "@budibase/backend-core": "2.6.19-alpha.30",
50
+ "@budibase/client": "2.6.19-alpha.30",
51
+ "@budibase/pro": "2.6.19-alpha.30",
52
+ "@budibase/shared-core": "2.6.19-alpha.30",
53
+ "@budibase/string-templates": "2.6.19-alpha.30",
54
+ "@budibase/types": "2.6.19-alpha.30",
55
55
  "@bull-board/api": "3.7.0",
56
56
  "@bull-board/koa": "3.9.4",
57
57
  "@elastic/elasticsearch": "7.10.0",
@@ -195,5 +195,5 @@
195
195
  }
196
196
  }
197
197
  },
198
- "gitHead": "e249a0693272bd111ad57e2b97602b33dc9920c1"
198
+ "gitHead": "c62ae2d9ea7f29de54c4cb6ef9a8f22e82eb8460"
199
199
  }
@@ -26,7 +26,10 @@ import {
26
26
  env as envCore,
27
27
  } from "@budibase/backend-core"
28
28
  import { USERS_TABLE_SCHEMA } from "../../constants"
29
- import { buildDefaultDocs } from "../../db/defaultData/datasource_bb_default"
29
+ import {
30
+ DEFAULT_BB_DATASOURCE_ID,
31
+ buildDefaultDocs,
32
+ } from "../../db/defaultData/datasource_bb_default"
30
33
  import { removeAppFromUserRoles } from "../../utilities/workerRequests"
31
34
  import { stringToReadStream, isQsTrue } from "../../utilities"
32
35
  import { getLocksById, doesUserHaveLock } from "../../utilities/redis"
@@ -111,11 +114,7 @@ function checkAppName(
111
114
  }
112
115
  }
113
116
 
114
- async function createInstance(
115
- appId: string,
116
- template: any,
117
- includeSampleData: boolean
118
- ) {
117
+ async function createInstance(appId: string, template: any) {
119
118
  const db = context.getAppDB()
120
119
  await db.put({
121
120
  _id: "_design/database",
@@ -142,21 +141,25 @@ async function createInstance(
142
141
  } else {
143
142
  // create the users table
144
143
  await db.put(USERS_TABLE_SCHEMA)
145
-
146
- if (includeSampleData) {
147
- // create ootb stock db
148
- await addDefaultTables(db)
149
- }
150
144
  }
151
145
 
152
146
  return { _id: appId }
153
147
  }
154
148
 
155
- async function addDefaultTables(db: Database) {
156
- const defaultDbDocs = buildDefaultDocs()
149
+ export const addSampleData = async (ctx: UserCtx) => {
150
+ const db = context.getAppDB()
157
151
 
158
- // add in the default db data docs - tables, datasource, rows and links
159
- await db.bulkDocs([...defaultDbDocs])
152
+ try {
153
+ // Check if default datasource exists before creating it
154
+ await sdk.datasources.get(DEFAULT_BB_DATASOURCE_ID)
155
+ } catch (err: any) {
156
+ const defaultDbDocs = buildDefaultDocs()
157
+
158
+ // add in the default db data docs - tables, datasource, rows and links
159
+ await db.bulkDocs([...defaultDbDocs])
160
+ }
161
+
162
+ ctx.status = 200
160
163
  }
161
164
 
162
165
  export async function fetch(ctx: UserCtx) {
@@ -248,16 +251,11 @@ async function performAppCreate(ctx: UserCtx) {
248
251
  if (ctx.request.files && ctx.request.files.templateFile) {
249
252
  instanceConfig.file = ctx.request.files.templateFile
250
253
  }
251
- const includeSampleData = isQsTrue(ctx.request.body.sampleData)
252
254
  const tenantId = tenancy.isMultiTenant() ? tenancy.getTenantId() : null
253
255
  const appId = generateDevAppID(generateAppID(tenantId))
254
256
 
255
257
  return await context.doInAppContext(appId, async () => {
256
- const instance = await createInstance(
257
- appId,
258
- instanceConfig,
259
- includeSampleData
260
- )
258
+ const instance = await createInstance(appId, instanceConfig)
261
259
  const db = context.getAppDB()
262
260
 
263
261
  let newApplication: App = {
@@ -38,6 +38,11 @@ router
38
38
  authorized(permissions.BUILDER),
39
39
  controller.revertClient
40
40
  )
41
+ .post(
42
+ "/api/applications/:appId/sample",
43
+ authorized(permissions.BUILDER),
44
+ controller.addSampleData
45
+ )
41
46
  .post(
42
47
  "/api/applications/:appId/publish",
43
48
  authorized(permissions.BUILDER),