Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Change to make tables name similar to service #7906

Merged
merged 8 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/server-core/migration.stub
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { Knex } from 'knex'

const TABLE_NAME = 'TABLE_NAME'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
Expand Down
11 changes: 5 additions & 6 deletions packages/server-core/src/analytics/analytics/analytics.seed.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Knex } from 'knex'
import { v4 } from 'uuid'

import { analyticsPath } from '@etherealengine/engine/src/schemas/analytics/analytics.schema'
import appConfig from '@etherealengine/server-core/src/appconfig'

import { getDateTimeSql } from '../../util/get-datetime-sql'

const TABLE_NAME = 'analytics'

export async function seed(knex: Knex): Promise<void> {
const { testEnabled } = appConfig
const { forceRefresh } = appConfig.db
Expand Down Expand Up @@ -42,15 +41,15 @@ export async function seed(knex: Knex): Promise<void> {

if (forceRefresh || testEnabled) {
// Deletes ALL existing entries
await knex(TABLE_NAME).del()
await knex(analyticsPath).del()

// Inserts seed entries
await knex(TABLE_NAME).insert(seedData)
await knex(analyticsPath).insert(seedData)
} else {
for (const item of seedData) {
const existingData = await knex(TABLE_NAME).where('count', item.count).andWhere('type', item.type)
const existingData = await knex(analyticsPath).where('count', item.count).andWhere('type', item.type)
if (existingData.length === 0) {
await knex(TABLE_NAME).insert(item)
await knex(analyticsPath).insert(item)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Knex } from 'knex'

const TABLE_NAME = 'analytics'
import { analyticsPath } from '@etherealengine/engine/src/schemas/analytics/analytics.schema'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const tableExists = await knex.schema.hasTable(analyticsPath)

if (tableExists === false) {
await knex.schema.createTable(TABLE_NAME, (table) => {
await knex.schema.createTable(analyticsPath, (table) => {
table.string('id', 36).primary()
table.integer('count').nullable()
table.string('type', 255).nullable()
Expand All @@ -25,9 +25,9 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const tableExists = await knex.schema.hasTable(analyticsPath)

if (tableExists === true) {
await knex.schema.dropTable(TABLE_NAME)
await knex.schema.dropTable(analyticsPath)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Knex } from 'knex'

const TABLE_NAME = 'route'
import { routePath } from '@etherealengine/engine/src/schemas/route/route.schema'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const tableExists = await knex.schema.hasTable(routePath)

if (tableExists === false) {
await knex.schema.createTable(TABLE_NAME, (table) => {
await knex.schema.createTable(routePath, (table) => {
table.string('id', 36).primary()
table.string('project', 255).nullable()
table.string('route', 255).nullable()
Expand All @@ -25,9 +25,9 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const tableExists = await knex.schema.hasTable(routePath)

if (tableExists === true) {
await knex.schema.dropTable(TABLE_NAME)
await knex.schema.dropTable(routePath)
}
}
11 changes: 5 additions & 6 deletions packages/server-core/src/route/route/route.seed.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Knex } from 'knex'
import { v4 } from 'uuid'

import { routePath } from '@etherealengine/engine/src/schemas/route/route.schema'
import appConfig from '@etherealengine/server-core/src/appconfig'

import { getDateTimeSql } from '../../util/get-datetime-sql'

const TABLE_NAME = 'route'

export async function seed(knex: Knex): Promise<void> {
const { testEnabled } = appConfig
const { forceRefresh } = appConfig.db
Expand Down Expand Up @@ -46,15 +45,15 @@ export async function seed(knex: Knex): Promise<void> {

if (forceRefresh || testEnabled) {
// Deletes ALL existing entries
await knex(TABLE_NAME).del()
await knex(routePath).del()

// Inserts seed entries
await knex(TABLE_NAME).insert(seedData)
await knex(routePath).insert(seedData)
} else {
for (const item of seedData) {
const existingData = await knex(TABLE_NAME).where('project', item.project).andWhere('route', item.route)
const existingData = await knex(routePath).where('project', item.project).andWhere('route', item.route)
if (existingData.length === 0) {
await knex(TABLE_NAME).insert(item)
await knex(routePath).insert(item)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Knex } from 'knex'
import { v4 } from 'uuid'

import { chargebeeSettingPath } from '@etherealengine/engine/src/schemas/setting/chargebee-setting.schema'
import appConfig from '@etherealengine/server-core/src/appconfig'

import { getDateTimeSql } from '../../util/get-datetime-sql'

const TABLE_NAME = 'chargebeeSetting'

export async function seed(knex: Knex): Promise<void> {
const { testEnabled } = appConfig
const { forceRefresh } = appConfig.db
Expand All @@ -22,15 +21,15 @@ export async function seed(knex: Knex): Promise<void> {

if (forceRefresh || testEnabled) {
// Deletes ALL existing entries
await knex(TABLE_NAME).del()
await knex(chargebeeSettingPath).del()

// Inserts seed entries
await knex(TABLE_NAME).insert(seedData)
await knex(chargebeeSettingPath).insert(seedData)
} else {
for (const item of seedData) {
const existingData = await knex(TABLE_NAME).where('url', item.url).andWhere('apiKey', item.apiKey)
const existingData = await knex(chargebeeSettingPath).where('url', item.url).andWhere('apiKey', item.apiKey)
if (existingData.length === 0) {
await knex(TABLE_NAME).insert(item)
await knex(chargebeeSettingPath).insert(item)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ declare module '@etherealengine/common/declarations' {

export default (app: Application): void => {
const options = {
//TODO: Ideally we should use `chargebeeSettingPath` variable, but since our table name is not `chargebee-setting` therefore hardcoded string is used.
name: 'chargebeeSetting', // chargebeeSettingPath,
name: chargebeeSettingPath,
paginate: app.get('paginate'),
Model: app.get('knexClient'),
multi: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import type { Knex } from 'knex'

const TABLE_NAME = 'chargebeeSetting'
import { chargebeeSettingPath } from '@etherealengine/engine/src/schemas/setting/chargebee-setting.schema'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const oldTableName = 'chargebeeSetting'

const oldNamedTableExists = await knex.schema.hasTable(oldTableName)
if (oldNamedTableExists) {
await knex.schema.renameTable(oldTableName, chargebeeSettingPath)
}

const tableExists = await knex.schema.hasTable(chargebeeSettingPath)

if (tableExists === false) {
await knex.schema.createTable(TABLE_NAME, (table) => {
await knex.schema.createTable(chargebeeSettingPath, (table) => {
table.string('id', 36).primary()
table.string('url', 255).nullable()
table.string('apiKey', 255).nullable()
Expand All @@ -25,9 +32,9 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const tableExists = await knex.schema.hasTable(chargebeeSettingPath)

if (tableExists === true) {
await knex.schema.dropTable(TABLE_NAME)
await knex.schema.dropTable(chargebeeSettingPath)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Knex } from 'knex'
import { v4 } from 'uuid'

import { coilSettingPath } from '@etherealengine/engine/src/schemas/setting/coil-setting.schema'
import appConfig from '@etherealengine/server-core/src/appconfig'

import { getDateTimeSql } from '../../util/get-datetime-sql'

const TABLE_NAME = 'coilSetting'

export async function seed(knex: Knex): Promise<void> {
const { testEnabled } = appConfig
const { forceRefresh } = appConfig.db
Expand All @@ -23,18 +22,18 @@ export async function seed(knex: Knex): Promise<void> {

if (forceRefresh || testEnabled) {
// Deletes ALL existing entries
await knex(TABLE_NAME).del()
await knex(coilSettingPath).del()

// Inserts seed entries
await knex(TABLE_NAME).insert(seedData)
await knex(coilSettingPath).insert(seedData)
} else {
for (const item of seedData) {
const existingData = await knex(TABLE_NAME)
const existingData = await knex(coilSettingPath)
.where('paymentPointer', item.paymentPointer)
.andWhere('clientId', item.clientId)
.andWhere('clientSecret', item.clientSecret)
if (existingData.length === 0) {
await knex(TABLE_NAME).insert(item)
await knex(coilSettingPath).insert(item)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ declare module '@etherealengine/common/declarations' {

export default (app: Application): void => {
const options = {
//TODO: Ideally we should use `coilSettingPath` variable, but since our table name is not `coil-setting` therefore hardcoded string is used.
name: 'coilSetting', // coilSettingPath,
name: coilSettingPath,
paginate: app.get('paginate'),
Model: app.get('knexClient'),
multi: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import type { Knex } from 'knex'

const TABLE_NAME = 'coilSetting'
import { coilSettingPath } from '@etherealengine/engine/src/schemas/setting/coil-setting.schema'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const oldTableName = 'coilSetting'

const oldNamedTableExists = await knex.schema.hasTable(oldTableName)
if (oldNamedTableExists) {
await knex.schema.renameTable(oldTableName, coilSettingPath)
}

const tableExists = await knex.schema.hasTable(coilSettingPath)

if (tableExists === false) {
await knex.schema.createTable(TABLE_NAME, (table) => {
await knex.schema.createTable(coilSettingPath, (table) => {
table.string('id', 36).primary()
table.string('paymentPointer', 255).nullable()
table.string('clientId', 255).nullable()
Expand All @@ -26,9 +33,9 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const tableExists = await knex.schema.hasTable(coilSettingPath)

if (tableExists === true) {
await knex.schema.dropTable(TABLE_NAME)
await knex.schema.dropTable(coilSettingPath)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Knex } from 'knex'
import { v4 } from 'uuid'

import { emailSettingPath } from '@etherealengine/engine/src/schemas/setting/email-setting.schema'
import appConfig from '@etherealengine/server-core/src/appconfig'

import { getDateTimeSql } from '../../util/get-datetime-sql'

const TABLE_NAME = 'emailSetting'

export async function seed(knex: Knex): Promise<void> {
const { testEnabled } = appConfig
const { forceRefresh } = appConfig.db
Expand Down Expand Up @@ -42,18 +41,18 @@ export async function seed(knex: Knex): Promise<void> {

if (forceRefresh || testEnabled) {
// Deletes ALL existing entries
await knex(TABLE_NAME).del()
await knex(emailSettingPath).del()

// Inserts seed entries
await knex(TABLE_NAME).insert(seedData)
await knex(emailSettingPath).insert(seedData)
} else {
for (const item of seedData) {
const existingData = await knex(TABLE_NAME)
const existingData = await knex(emailSettingPath)
.where('smtp', item.smtp)
.andWhere('from', item.from)
.andWhere('subject', item.subject)
if (existingData.length === 0) {
await knex(TABLE_NAME).insert(item)
await knex(emailSettingPath).insert(item)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ declare module '@etherealengine/common/declarations' {

export default (app: Application): void => {
const options = {
//TODO: Ideally we should use `emailSettingPath` variable, but since our table name is not `email-setting` therefore hardcoded string is used.
name: 'emailSetting', // emailSettingPath,
name: emailSettingPath,
paginate: app.get('paginate'),
Model: app.get('knexClient'),
multi: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import type { Knex } from 'knex'

const TABLE_NAME = 'emailSetting'
import { emailSettingPath } from '@etherealengine/engine/src/schemas/setting/email-setting.schema'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const oldTableName = 'emailSetting'

const oldNamedTableExists = await knex.schema.hasTable(oldTableName)
if (oldNamedTableExists) {
await knex.schema.renameTable(oldTableName, emailSettingPath)
}

const tableExists = await knex.schema.hasTable(emailSettingPath)

if (tableExists === false) {
await knex.schema.createTable(TABLE_NAME, (table) => {
await knex.schema.createTable(emailSettingPath, (table) => {
table.string('id', 36).primary()
table.json('smtp').nullable()
table.string('from', 255).nullable()
Expand All @@ -27,9 +34,9 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const tableExists = await knex.schema.hasTable(emailSettingPath)

if (tableExists === true) {
await knex.schema.dropTable(TABLE_NAME)
await knex.schema.dropTable(emailSettingPath)
}
}
Loading