mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-07-18 17:01:57 +00:00
Database structure for NEB
This commit is contained in:
parent
c5b803343e
commit
5314bea52d
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
77
src/db/migrations/20171224140745-AddNeb.ts
Normal file
77
src/db/migrations/20171224140745-AddNeb.ts
Normal 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"));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
26
src/db/models/NebBotUser.ts
Normal file
26
src/db/models/NebBotUser.ts
Normal 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;
|
||||
}
|
29
src/db/models/NebConfiguration.ts
Normal file
29
src/db/models/NebConfiguration.ts
Normal 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;
|
||||
}
|
37
src/db/models/NebIntegration.ts
Normal file
37
src/db/models/NebIntegration.ts
Normal 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;
|
||||
}
|
31
src/db/models/NebNotificationUser.ts
Normal file
31
src/db/models/NebNotificationUser.ts
Normal 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;
|
||||
}
|
|
@ -33,7 +33,4 @@ export default class UserScalarToken extends Model<UserScalarToken> {
|
|||
@Column
|
||||
@ForeignKey(() => Upstream)
|
||||
upstreamId?: number;
|
||||
|
||||
@BelongsTo(() => Upstream)
|
||||
upstream: Upstream;
|
||||
}
|
Loading…
Reference in New Issue
Block a user