u
This commit is contained in:
@@ -11,7 +11,6 @@ export const TABLES = [
|
||||
'modelmessage',
|
||||
'modelconversation',
|
||||
'companyuser',
|
||||
'syncpos',
|
||||
'companysetting',
|
||||
'posterminalcategory',
|
||||
'posterminal',
|
||||
|
||||
@@ -6,7 +6,11 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY id
|
||||
@@ -21,7 +25,11 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE id = @id
|
||||
`;
|
||||
@@ -35,29 +43,39 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE pairingpin = @pairingpin
|
||||
`;
|
||||
|
||||
export const PAIR = `
|
||||
UPDATE posterminal
|
||||
SET token = @token, paired_at = @pairedAt, clientserial = @clientserial, pairingpin = ''
|
||||
SET token = @token, paired_at = @pairedAt, clientserial = @clientserial, pairingpin = NULL, lastseen_at = @pairedAt, updated_at = SYSUTCDATETIME()
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO posterminal (company_id, name, token, pairingpin, paired_at, clientserial, maxknowntombstoneid)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin, INSERTED.paired_at AS pairedAt, INSERTED.clientserial AS clientserial, INSERTED.maxknowntombstoneid AS maxknowntombstoneid
|
||||
VALUES (@companyId, @name, @token, @pairingpin, @pairedAt, @clientserial, @maxknowntombstoneid)
|
||||
INSERT INTO posterminal (company_id, name, token, pairingpin, paired_at, clientserial, maxknowntombstoneid, root_category_id, sync_root_articles, lastseen_at, updated_at)
|
||||
OUTPUT INSERTED.id, INSERTED.name, INSERTED.token, INSERTED.pairingpin, INSERTED.paired_at AS pairedAt, INSERTED.clientserial AS clientserial, INSERTED.maxknowntombstoneid AS maxknowntombstoneid, INSERTED.root_category_id AS rootCategoryId, INSERTED.sync_root_articles AS syncRootArticles, INSERTED.lastseen_at AS lastseenAt, INSERTED.updated_at AS updatedAt
|
||||
VALUES (@companyId, @name, @token, @pairingpin, @pairedAt, @clientserial, @maxknowntombstoneid, @rootCategoryId, @syncRootArticles, @lastseenAt, SYSUTCDATETIME())
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE posterminal
|
||||
SET name = @name, token = @token, pairingpin = @pairingpin, paired_at = @pairedAt, clientserial = @clientserial, maxknowntombstoneid = @maxknowntombstoneid
|
||||
SET name = @name, token = @token, pairingpin = @pairingpin, paired_at = @pairedAt, clientserial = @clientserial, maxknowntombstoneid = @maxknowntombstoneid, root_category_id = @rootCategoryId, sync_root_articles = @syncRootArticles, lastseen_at = @lastseenAt, updated_at = SYSUTCDATETIME()
|
||||
WHERE id = @id AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const TOUCH_LASTSEEN = `
|
||||
UPDATE posterminal
|
||||
SET lastseen_at = SYSUTCDATETIME()
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const SET_MAX_KNOWN_TOMBSTONE_ID = `
|
||||
UPDATE posterminal
|
||||
SET maxknowntombstoneid = @maxknowntombstoneid
|
||||
@@ -132,7 +150,11 @@ SELECT
|
||||
pairingpin,
|
||||
paired_at AS pairedAt,
|
||||
clientserial AS clientserial,
|
||||
maxknowntombstoneid AS maxknowntombstoneid
|
||||
maxknowntombstoneid AS maxknowntombstoneid,
|
||||
root_category_id AS rootCategoryId,
|
||||
sync_root_articles AS syncRootArticles,
|
||||
lastseen_at AS lastseenAt,
|
||||
updated_at AS updatedAt
|
||||
FROM posterminal
|
||||
WHERE token = @token
|
||||
`;
|
||||
|
||||
@@ -840,21 +840,6 @@ BEGIN
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_SYNCPOS = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'syncpos')
|
||||
BEGIN
|
||||
CREATE TABLE syncpos (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
paircode NVARCHAR(50) NOT NULL,
|
||||
token NVARCHAR(255) NULL,
|
||||
CONSTRAINT FK_syncpos_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
CONSTRAINT UQ_syncpos_paircode UNIQUE (paircode),
|
||||
CONSTRAINT UQ_syncpos_token UNIQUE (token)
|
||||
);
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_COMPANYSETTING = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'companysetting')
|
||||
BEGIN
|
||||
@@ -879,21 +864,19 @@ BEGIN
|
||||
company_id INT NOT NULL,
|
||||
name NVARCHAR(255) NOT NULL,
|
||||
token NVARCHAR(255) NULL,
|
||||
pairingpin NVARCHAR(50) NOT NULL,
|
||||
pairingpin NVARCHAR(50) NULL,
|
||||
paired_at DATETIME2 NULL,
|
||||
clientserial NVARCHAR(255) NULL,
|
||||
maxknowntombstoneid INT NULL,
|
||||
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||
root_category_id INT NULL,
|
||||
sync_root_articles BIT NOT NULL CONSTRAINT DF_posterminal_sync_root_articles DEFAULT 1,
|
||||
lastseen_at DATETIME2 NULL,
|
||||
updated_at DATETIME2 NOT NULL CONSTRAINT DF_posterminal_updated_at DEFAULT SYSUTCDATETIME(),
|
||||
CONSTRAINT FK_posterminal_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_posterminal_root_category FOREIGN KEY (root_category_id) REFERENCES category(id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX UQ_posterminal_token ON posterminal(token) WHERE token IS NOT NULL;
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('posterminal') AND name = 'maxknowntombstoneid')
|
||||
BEGIN
|
||||
ALTER TABLE posterminal ADD maxknowntombstoneid INT NULL;
|
||||
END
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_POSTERMINALCATEGORY = `
|
||||
@@ -1163,7 +1146,6 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_ARTICLETOMBSTONE,
|
||||
INIT_ENTITYHISTORY,
|
||||
INIT_COMPANYHISTORY,
|
||||
INIT_SYNCPOS,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
INIT_POSTERMINALCATEGORY,
|
||||
|
||||
Reference in New Issue
Block a user