diff --git a/src/db/DimensionStore.ts b/src/db/DimensionStore.ts index a8f448f..34e7d2a 100644 --- a/src/db/DimensionStore.ts +++ b/src/db/DimensionStore.ts @@ -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, ]); } diff --git a/src/db/migrations/20171224140745-AddNeb.ts b/src/db/migrations/20171224140745-AddNeb.ts new file mode 100644 index 0000000..4fcf944 --- /dev/null +++ b/src/db/migrations/20171224140745-AddNeb.ts @@ -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")); + } +} \ No newline at end of file diff --git a/src/db/models/AppServiceUser.ts b/src/db/models/AppServiceUser.ts index a4e51fb..c7eb137 100644 --- a/src/db/models/AppServiceUser.ts +++ b/src/db/models/AppServiceUser.ts @@ -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 { @Column @ForeignKey(() => AppService) appserviceId: string; - - @BelongsTo(() => AppService) - appservice: AppService; } \ No newline at end of file diff --git a/src/db/models/NebBotUser.ts b/src/db/models/NebBotUser.ts new file mode 100644 index 0000000..70d7509 --- /dev/null +++ b/src/db/models/NebBotUser.ts @@ -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 { + @PrimaryKey + @AutoIncrement + @Column + id: number; + + @Column + serviceId: string; + + @Column + @ForeignKey(() => AppServiceUser) + appserviceUserId: string; + + @Column + @ForeignKey(() => NebIntegration) + integrationId: number; +} \ No newline at end of file diff --git a/src/db/models/NebConfiguration.ts b/src/db/models/NebConfiguration.ts new file mode 100644 index 0000000..718607f --- /dev/null +++ b/src/db/models/NebConfiguration.ts @@ -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 { + @PrimaryKey + @AutoIncrement + @Column + id: number; + + @AllowNull + @Column + adminUrl?: string; + + @AllowNull + @Column + @ForeignKey(() => AppService) + appserviceId?: string; + + @AllowNull + @Column + @ForeignKey(() => Upstream) + upstreamId?: number; +} \ No newline at end of file diff --git a/src/db/models/NebIntegration.ts b/src/db/models/NebIntegration.ts new file mode 100644 index 0000000..84cab20 --- /dev/null +++ b/src/db/models/NebIntegration.ts @@ -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 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; +} \ No newline at end of file diff --git a/src/db/models/NebNotificationUser.ts b/src/db/models/NebNotificationUser.ts new file mode 100644 index 0000000..d72dff4 --- /dev/null +++ b/src/db/models/NebNotificationUser.ts @@ -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 { + @PrimaryKey + @AutoIncrement + @Column + id: number; + + @Column + serviceId: string; + + @Column + @ForeignKey(() => User) + ownerId: string; + + @Column + @ForeignKey(() => AppServiceUser) + appserviceUserId: string; + + @Column + @ForeignKey(() => NebIntegration) + integrationId: number; +} \ No newline at end of file diff --git a/src/db/models/UserScalarToken.ts b/src/db/models/UserScalarToken.ts index 522d573..e086a04 100644 --- a/src/db/models/UserScalarToken.ts +++ b/src/db/models/UserScalarToken.ts @@ -33,7 +33,4 @@ export default class UserScalarToken extends Model { @Column @ForeignKey(() => Upstream) upstreamId?: number; - - @BelongsTo(() => Upstream) - upstream: Upstream; } \ No newline at end of file