u
This commit is contained in:
@@ -34,6 +34,7 @@ export const TABLES = [
|
||||
'articleean',
|
||||
'articlehistory',
|
||||
'entityhistory',
|
||||
'companyhistory',
|
||||
'entityaddress',
|
||||
'entitycontact',
|
||||
'article',
|
||||
|
||||
19
src/providers/mssql/queries/companyhistory.js
Normal file
19
src/providers/mssql/queries/companyhistory.js
Normal file
@@ -0,0 +1,19 @@
|
||||
export const INSERT = `
|
||||
INSERT INTO companyhistory (company_id, companyuser_id, [text])
|
||||
OUTPUT INSERTED.id, INSERTED.companyuser_id AS companyuserId, INSERTED.[date], INSERTED.[text]
|
||||
VALUES (@companyId, @companyuserId, @text)
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY_ID = `
|
||||
SELECT id, companyuser_id AS companyuserId, [date], [text]
|
||||
FROM companyhistory
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY [date] DESC, id DESC
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY_ID_LIMITED = `
|
||||
SELECT TOP (@limit) id, companyuser_id AS companyuserId, [date], [text]
|
||||
FROM companyhistory
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY [date] DESC, id DESC
|
||||
`;
|
||||
@@ -374,6 +374,20 @@ BEGIN
|
||||
);
|
||||
END
|
||||
`;
|
||||
export const INIT_COMPANYHISTORY = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'companyhistory')
|
||||
BEGIN
|
||||
CREATE TABLE companyhistory (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
companyuser_id INT NULL,
|
||||
[date] DATETIME2 NOT NULL CONSTRAINT DF_companyhistory_date DEFAULT SYSUTCDATETIME(),
|
||||
[text] NVARCHAR(MAX) NOT NULL,
|
||||
CONSTRAINT FK_companyhistory_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_companyhistory_companyuser FOREIGN KEY (companyuser_id) REFERENCES companyuser(id) ON DELETE SET NULL
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLETOMBSTONE = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articletombstone')
|
||||
@@ -1147,6 +1161,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLEHISTORY,
|
||||
INIT_ARTICLETOMBSTONE,
|
||||
INIT_ENTITYHISTORY,
|
||||
INIT_COMPANYHISTORY,
|
||||
INIT_SYNCPOS,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
|
||||
13
src/providers/sqlite3/queries/companyhistory.js
Normal file
13
src/providers/sqlite3/queries/companyhistory.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import * as source from '../../mssql/queries/companyhistory.js';
|
||||
import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'companyhistory');
|
||||
export const { INSERT, LIST_BY_COMPANY_ID } = queries;
|
||||
|
||||
export const LIST_BY_COMPANY_ID_LIMITED = `
|
||||
SELECT id, companyuser_id AS companyuserId, date, text
|
||||
FROM companyhistory
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY date DESC, id DESC
|
||||
LIMIT @limit
|
||||
`;
|
||||
@@ -536,6 +536,17 @@ CREATE TABLE IF NOT EXISTS articlehistory (
|
||||
FOREIGN KEY (companyuser_id) REFERENCES companyuser(id) ON DELETE SET NULL
|
||||
);
|
||||
`;
|
||||
export const INIT_COMPANYHISTORY = `
|
||||
CREATE TABLE IF NOT EXISTS companyhistory (
|
||||
id INTEGER PRIMARY KEY,
|
||||
company_id INTEGER NOT NULL,
|
||||
companyuser_id INTEGER,
|
||||
"date" TEXT NOT NULL DEFAULT (${UTC_NOW}),
|
||||
"text" TEXT NOT NULL,
|
||||
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (companyuser_id) REFERENCES companyuser(id) ON DELETE SET NULL
|
||||
);
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLETOMBSTONE = `
|
||||
CREATE TABLE IF NOT EXISTS articletombstone (
|
||||
@@ -818,6 +829,7 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLEHISTORY,
|
||||
INIT_ARTICLETOMBSTONE,
|
||||
INIT_ENTITYHISTORY,
|
||||
INIT_COMPANYHISTORY,
|
||||
INIT_SYNCPOS,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
|
||||
Reference in New Issue
Block a user