Database structure for NEB

This commit is contained in:
Travis Ralston 2017-12-24 14:16:39 -07:00
parent c5b803343e
commit 5314bea52d
8 changed files with 209 additions and 7 deletions

View File

@ -10,6 +10,10 @@ import * as path from "path";
import * as Umzug from "umzug";
import AppService from "./models/AppService";
import AppServiceUser from "./models/AppServiceUser";
import NebConfiguration from "./models/NebConfiguration";
import NebIntegration from "./models/NebIntegration";
import NebBotUser from "./models/NebBotUser";
import NebNotificationUser from "./models/NebNotificationUser";
class _DimensionStore {
private sequelize: Sequelize;
@ -30,6 +34,10 @@ class _DimensionStore {
WidgetRecord,
AppService,
AppServiceUser,
NebConfiguration,
NebIntegration,
NebBotUser,
NebNotificationUser,
]);
}

View File

@ -0,0 +1,77 @@
import { QueryInterface } from "sequelize";
import { DataType } from "sequelize-typescript";
import * as Promise from "bluebird";
export default {
up: (queryInterface: QueryInterface) => {
return Promise.resolve()
.then(() => queryInterface.createTable("dimension_neb_configurations", {
"id": {type: DataType.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false},
"appserviceId": {
type: DataType.STRING, allowNull: true,
references: {model: "dimension_appservice", key: "id"},
onUpdate: "cascade", onDelete: "cascade",
},
"upstreamId": {
type: DataType.INTEGER, allowNull: true,
references: {model: "dimension_upstreams", key: "id"},
onUpdate: "cascade", onDelete: "cascade",
},
"adminUrl": {type: DataType.STRING, allowNull: true},
}))
.then(() => queryInterface.createTable("dimension_neb_integrations", {
"id": {type: DataType.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false},
"type": {type: DataType.STRING, allowNull: false},
"name": {type: DataType.STRING, allowNull: false},
"avatarUrl": {type: DataType.STRING, allowNull: false},
"description": {type: DataType.STRING, allowNull: false},
"isEnabled": {type: DataType.BOOLEAN, allowNull: false},
"isPublic": {type: DataType.BOOLEAN, allowNull: false},
"nebId": {
type: DataType.INTEGER, allowNull: false,
references: {model: "dimension_neb_configurations", key: "id"},
onUpdate: "cascade", onDelete: "cascade",
},
}))
.then(() => queryInterface.createTable("dimension_neb_bot_users", {
"id": {type: DataType.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false},
"serviceId": {type: DataType.STRING, allowNull: false},
"appserviceUserId": {
type: DataType.STRING, allowNull: false,
references: {model: "dimension_appservice_users", key: "id"},
onUpdate: "cascade", onDelete: "cascade",
},
"integrationId": {
type: DataType.INTEGER, allowNull: false,
references: {model: "dimension_neb_integrations", key: "id"},
onUpdate: "cascade", onDelete: "cascade",
},
}))
.then(() => queryInterface.createTable("dimension_neb_notification_users", {
"id": {type: DataType.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false},
"serviceId": {type: DataType.STRING, allowNull: false},
"ownerId": {
type: DataType.STRING, allowNull: false,
references: {model: "dimension_users", key: "userId"},
onUpdate: "cascade", onDelete: "cascade",
},
"appserviceUserId": {
type: DataType.STRING, allowNull: false,
references: {model: "dimension_appservice_users", key: "id"},
onUpdate: "cascade", onDelete: "cascade",
},
"integrationId": {
type: DataType.INTEGER, allowNull: false,
references: {model: "dimension_neb_integrations", key: "id"},
onUpdate: "cascade", onDelete: "cascade",
},
}));
},
down: (queryInterface: QueryInterface) => {
return Promise.resolve()
.then(() => queryInterface.dropTable("dimension_neb_notification_users"))
.then(() => queryInterface.dropTable("dimension_neb_bot_users"))
.then(() => queryInterface.dropTable("dimension_neb_integrations"))
.then(() => queryInterface.dropTable("dimension_neb_configurations"));
}
}

View File

@ -1,4 +1,4 @@
import { AllowNull, BelongsTo, Column, ForeignKey, Model, PrimaryKey, Table } from "sequelize-typescript";
import { AllowNull, Column, ForeignKey, Model, PrimaryKey, Table } from "sequelize-typescript";
import AppService from "./AppService";
@Table({
@ -25,7 +25,4 @@ export default class AppServiceUser extends Model<AppServiceUser> {
@Column
@ForeignKey(() => AppService)
appserviceId: string;
@BelongsTo(() => AppService)
appservice: AppService;
}

View File

@ -0,0 +1,26 @@
import { AutoIncrement, Column, ForeignKey, Model, PrimaryKey, Table } from "sequelize-typescript";
import AppServiceUser from "./AppServiceUser";
import NebIntegration from "./NebIntegration";
@Table({
tableName: "dimension_neb_bot_users",
underscoredAll: false,
timestamps: false,
})
export default class NebBotUser extends Model<NebBotUser> {
@PrimaryKey
@AutoIncrement
@Column
id: number;
@Column
serviceId: string;
@Column
@ForeignKey(() => AppServiceUser)
appserviceUserId: string;
@Column
@ForeignKey(() => NebIntegration)
integrationId: number;
}

View File

@ -0,0 +1,29 @@
import { AllowNull, AutoIncrement, Column, ForeignKey, Model, PrimaryKey, Table } from "sequelize-typescript";
import Upstream from "./Upstream";
import AppService from "./AppService";
@Table({
tableName: "dimension_neb_configurations",
underscoredAll: false,
timestamps: false,
})
export default class NebConfiguration extends Model<NebConfiguration> {
@PrimaryKey
@AutoIncrement
@Column
id: number;
@AllowNull
@Column
adminUrl?: string;
@AllowNull
@Column
@ForeignKey(() => AppService)
appserviceId?: string;
@AllowNull
@Column
@ForeignKey(() => Upstream)
upstreamId?: number;
}

View File

@ -0,0 +1,37 @@
import { AutoIncrement, Column, ForeignKey, Model, PrimaryKey, Table } from "sequelize-typescript";
import { IntegrationRecord } from "./IntegrationRecord";
import NebConfiguration from "./NebConfiguration";
@Table({
tableName: "dimension_neb_integrations",
underscoredAll: false,
timestamps: false,
})
export default class NebIntegration extends Model<NebIntegration> implements IntegrationRecord {
@PrimaryKey
@AutoIncrement
@Column
id: number;
@Column
type: string;
@Column
name: string;
@Column
avatarUrl: string;
@Column
description: string;
@Column
isEnabled: boolean;
@Column
isPublic: boolean;
@Column
@ForeignKey(() => NebConfiguration)
nebId: number;
}

View File

@ -0,0 +1,31 @@
import { AutoIncrement, Column, ForeignKey, Model, PrimaryKey, Table } from "sequelize-typescript";
import AppServiceUser from "./AppServiceUser";
import NebIntegration from "./NebIntegration";
import User from "./User";
@Table({
tableName: "dimension_neb_notification_users",
underscoredAll: false,
timestamps: false,
})
export default class NebNotificationUser extends Model<NebNotificationUser> {
@PrimaryKey
@AutoIncrement
@Column
id: number;
@Column
serviceId: string;
@Column
@ForeignKey(() => User)
ownerId: string;
@Column
@ForeignKey(() => AppServiceUser)
appserviceUserId: string;
@Column
@ForeignKey(() => NebIntegration)
integrationId: number;
}

View File

@ -33,7 +33,4 @@ export default class UserScalarToken extends Model<UserScalarToken> {
@Column
@ForeignKey(() => Upstream)
upstreamId?: number;
@BelongsTo(() => Upstream)
upstream: Upstream;
}