2020-10-28 13:25:18 +00:00
|
|
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
|
|
|
//
|
|
|
|
// 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 { CoreAppSchema } from '@services/app';
|
2020-11-19 15:35:17 +00:00
|
|
|
import { CoreSiteSchema } from '@services/sites';
|
2020-10-28 13:25:18 +00:00
|
|
|
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Database variables for CoreSites service.
|
|
|
|
*/
|
|
|
|
export const SITES_TABLE_NAME = 'sites_2';
|
|
|
|
export const SCHEMA_VERSIONS_TABLE_NAME = 'schema_versions';
|
|
|
|
|
2022-06-13 06:27:59 +00:00
|
|
|
/**
|
|
|
|
* Database variables for CoreSite class.
|
|
|
|
*/
|
2022-11-30 11:14:18 +00:00
|
|
|
export const WS_CACHE_TABLE = 'wscache_2';
|
2022-06-13 06:27:59 +00:00
|
|
|
export const CONFIG_TABLE = 'core_site_config';
|
|
|
|
export const LAST_VIEWED_TABLE = 'core_site_last_viewed';
|
|
|
|
|
2020-10-28 13:25:18 +00:00
|
|
|
// Schema to register in App DB.
|
|
|
|
export const APP_SCHEMA: CoreAppSchema = {
|
|
|
|
name: 'CoreSitesProvider',
|
|
|
|
version: 2,
|
|
|
|
tables: [
|
|
|
|
{
|
|
|
|
name: SITES_TABLE_NAME,
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
name: 'id',
|
|
|
|
type: 'TEXT',
|
|
|
|
primaryKey: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'siteUrl',
|
|
|
|
type: 'TEXT',
|
|
|
|
notNull: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'token',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'info',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'privateToken',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'config',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'loggedOut',
|
|
|
|
type: 'INTEGER',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'oauthId',
|
|
|
|
type: 'INTEGER',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
async migrate(db: SQLiteDB, oldVersion: number): Promise<void> {
|
|
|
|
if (oldVersion < 2) {
|
2021-03-18 15:01:05 +00:00
|
|
|
await db.migrateTable('sites', SITES_TABLE_NAME);
|
2020-10-28 13:25:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Schema to register for Site DB.
|
|
|
|
export const SITE_SCHEMA: CoreSiteSchema = {
|
|
|
|
name: 'CoreSitesProvider',
|
2022-11-30 11:14:18 +00:00
|
|
|
version: 3,
|
|
|
|
canBeCleared: [WS_CACHE_TABLE],
|
|
|
|
tables: [
|
|
|
|
{
|
|
|
|
name: WS_CACHE_TABLE,
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
name: 'id',
|
|
|
|
type: 'TEXT',
|
|
|
|
primaryKey: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'data',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'key',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'expirationTime',
|
|
|
|
type: 'INTEGER',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'component',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'componentId',
|
|
|
|
type: 'INTEGER',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-10-28 13:25:18 +00:00
|
|
|
{
|
2022-06-13 06:27:59 +00:00
|
|
|
name: CONFIG_TABLE,
|
2020-10-28 13:25:18 +00:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
name: 'name',
|
|
|
|
type: 'TEXT',
|
|
|
|
unique: true,
|
|
|
|
notNull: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'value',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2022-02-28 11:38:46 +00:00
|
|
|
{
|
2022-06-13 06:27:59 +00:00
|
|
|
name: LAST_VIEWED_TABLE,
|
2022-02-28 11:38:46 +00:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
name: 'component',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'id',
|
|
|
|
type: 'INTEGER',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'value',
|
|
|
|
type: 'TEXT',
|
|
|
|
notNull: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'data',
|
|
|
|
type: 'TEXT',
|
|
|
|
},
|
2022-03-09 13:38:00 +00:00
|
|
|
{
|
|
|
|
name: 'timeaccess',
|
|
|
|
type: 'INTEGER',
|
|
|
|
},
|
2022-02-28 11:38:46 +00:00
|
|
|
],
|
|
|
|
primaryKeys: ['component', 'id'],
|
|
|
|
},
|
2022-11-30 11:14:18 +00:00
|
|
|
],
|
2020-10-28 13:25:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Table for site DB to include the schema versions. It's not part of SITE_SCHEMA because it needs to be created first.
|
|
|
|
export const SCHEMA_VERSIONS_TABLE_SCHEMA: SQLiteDBTableSchema = {
|
|
|
|
name: SCHEMA_VERSIONS_TABLE_NAME,
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
name: 'name',
|
|
|
|
type: 'TEXT',
|
|
|
|
primaryKey: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'version',
|
|
|
|
type: 'INTEGER',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
export type SiteDBEntry = {
|
|
|
|
id: string;
|
|
|
|
siteUrl: string;
|
|
|
|
token: string;
|
2021-03-17 13:14:30 +00:00
|
|
|
info?: string | null;
|
2020-10-28 13:25:18 +00:00
|
|
|
privateToken: string;
|
2021-03-17 13:14:30 +00:00
|
|
|
config?: string | null;
|
2020-10-28 13:25:18 +00:00
|
|
|
loggedOut: number;
|
2021-03-17 13:14:30 +00:00
|
|
|
oauthId?: number | null;
|
2020-10-28 13:25:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type SchemaVersionsDBEntry = {
|
|
|
|
name: string;
|
|
|
|
version: number;
|
|
|
|
};
|
2022-06-13 06:27:59 +00:00
|
|
|
|
|
|
|
export type CoreSiteConfigDBRecord = {
|
|
|
|
name: string;
|
|
|
|
value: string | number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type CoreSiteWSCacheRecord = {
|
|
|
|
id: string;
|
|
|
|
data: string;
|
|
|
|
expirationTime: number;
|
|
|
|
key?: string;
|
|
|
|
component?: string;
|
|
|
|
componentId?: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type CoreSiteLastViewedDBRecord = {
|
|
|
|
component: string;
|
|
|
|
id: number;
|
|
|
|
value: string;
|
|
|
|
timeaccess: number;
|
|
|
|
data?: string;
|
|
|
|
};
|