Skip to content
Extraits de code Groupes Projets
Valider e3f747c3 rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

Add room schema

Bump schema
parent edb6ee35
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
/*
Copyright 2018 matrix-appservice-discord
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import {IDbSchema} from "./dbschema";
import {DiscordStore} from "../../store";
import { Log } from "../../log";
const log = new Log("SchemaV8");
export class Schema implements IDbSchema {
public description = "create room store tables";
public async run(store: DiscordStore): Promise<void> {
await store.create_table(`
CREATE TABLE remote_room_data (
room_id TEXT NOT NULL,
discord_guild TEXT NOT NULL,
discord_channel TEXT NOT NULL,
discord_name TEXT DEFAULT NULL,
discord_topic TEXT DEFAULT NULL,
discord_type TEXT DEFAULT NULL,
discord_iconurl TEXT DEFAULT NULL,
discord_iconurl_mxc TEXT DEFAULT NULL,
update_name NUMERIC DEFAULT 0,
update_topic NUMERIC DEFAULT 0,
update_icon NUMERIC DEFAULT 0,
plumbed NUMERIC DEFAULT 0,
PRIMARY KEY(room_id)
);`, "remote_room_data");
await store.create_table(`
CREATE TABLE room_entries (
id TEXT NOT NULL,
matrix_id TEXT,
remote_id TEXT,
PRIMARY KEY(id)
);`, "room_entries");
}
public async rollBack(store: DiscordStore): Promise<void> {
await store.db.Run(
`DROP TABLE IF EXISTS remote_room_data;`,
);
await store.db.Run(
`DROP TABLE IF EXISTS room_entries;`,
);
}
}
......@@ -18,23 +18,22 @@ import * as fs from "fs";
import { IDbSchema } from "./db/schema/dbschema";
import { IDbData} from "./db/dbdatainterface";
import { SQLite3 } from "./db/sqlite3";
export const CURRENT_SCHEMA = 7;
export const CURRENT_SCHEMA = 8;
import { Log } from "./log";
import { DiscordBridgeConfigDatabase } from "./config";
import { Postgres } from "./db/postgres";
import { IDatabaseConnector } from "./db/connector";
import { DbRoomStore } from "./db/roomstore";
const log = new Log("DiscordStore");
/**
* Stores data for specific users and data not specific to rooms.
*/
export class DiscordStore {
/**
* @param {string} filepath Location of the SQLite database file.
*/
public db: IDatabaseConnector;
private version: number;
private config: DiscordBridgeConfigDatabase;
private pRoomStore: DbRoomStore;
constructor(private configOrFile: DiscordBridgeConfigDatabase|string) {
if (typeof(configOrFile) === "string") {
this.config = new DiscordBridgeConfigDatabase();
......@@ -45,6 +44,10 @@ export class DiscordStore {
this.version = 0;
}
get roomStore() {
return this.pRoomStore;
}
public async backup_database(): Promise<void|{}> {
if (this.config.filename == null) {
log.warn("Backups not supported on non-sqlite connector");
......@@ -327,6 +330,7 @@ export class DiscordStore {
}
try {
this.db.Open();
this.pRoomStore = new DbRoomStore(this.db);
} catch (ex) {
log.error("Error opening database:", ex);
throw new Error("Couldn't open database. The appservice won't be able to continue.");
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter