tidy up temp scripts
parent
ee66338ee7
commit
2bed8f0289
|
|
@ -36,24 +36,29 @@ const user = {
|
||||||
};
|
};
|
||||||
function purgeTables() {
|
function purgeTables() {
|
||||||
console.time('purgeTables');
|
console.time('purgeTables');
|
||||||
|
const tablesToPurge = [
|
||||||
|
'WorkOrderMilestones',
|
||||||
|
'WorkOrderComments',
|
||||||
|
'WorkOrderLots',
|
||||||
|
'WorkOrderLotOccupancies',
|
||||||
|
'WorkOrders',
|
||||||
|
'LotOccupancyTransactions',
|
||||||
|
'LotOccupancyFees',
|
||||||
|
'LotOccupancyFields',
|
||||||
|
'LotOccupancyComments',
|
||||||
|
'LotOccupancyOccupants',
|
||||||
|
'LotOccupancies',
|
||||||
|
'LotFields',
|
||||||
|
'LotComments',
|
||||||
|
'Lots'
|
||||||
|
];
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
database.prepare('delete from WorkOrderMilestones').run();
|
for (const tableName of tablesToPurge) {
|
||||||
database.prepare('delete from WorkOrderComments').run();
|
database.prepare(`delete from ${tableName}`).run();
|
||||||
database.prepare('delete from WorkOrderLots').run();
|
|
||||||
database.prepare('delete from WorkOrderLotOccupancies').run();
|
|
||||||
database.prepare('delete from WorkOrders').run();
|
|
||||||
database.prepare('delete from LotOccupancyTransactions').run();
|
|
||||||
database.prepare('delete from LotOccupancyFees').run();
|
|
||||||
database.prepare('delete from LotOccupancyFields').run();
|
|
||||||
database.prepare('delete from LotOccupancyComments').run();
|
|
||||||
database.prepare('delete from LotOccupancyOccupants').run();
|
|
||||||
database.prepare('delete from LotOccupancies').run();
|
|
||||||
database.prepare('delete from LotFields').run();
|
|
||||||
database.prepare('delete from LotComments').run();
|
|
||||||
database.prepare('delete from Lots').run();
|
|
||||||
database
|
database
|
||||||
.prepare("delete from sqlite_sequence where name in ('Lots', 'LotComments', 'LotOccupancies', 'LotOccupancyComments', 'WorkOrders', 'WorkOrderComments', 'WorkOrderMilestones')")
|
.prepare('delete from sqlite_sequence where name = ?')
|
||||||
.run();
|
.run(tableName);
|
||||||
|
}
|
||||||
database.close();
|
database.close();
|
||||||
console.timeEnd('purgeTables');
|
console.timeEnd('purgeTables');
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +125,7 @@ async function getMap(dataRow) {
|
||||||
mapPostalCode: '',
|
mapPostalCode: '',
|
||||||
mapPhoneNumber: ''
|
mapPhoneNumber: ''
|
||||||
}, user);
|
}, user);
|
||||||
map = await getMapFromDatabase(mapId);
|
map = (await getMapFromDatabase(mapId));
|
||||||
}
|
}
|
||||||
mapCache.set(mapCacheKey, map);
|
mapCache.set(mapCacheKey, map);
|
||||||
return map;
|
return map;
|
||||||
|
|
|
||||||
|
|
@ -213,26 +213,32 @@ const user: recordTypes.PartialSession = {
|
||||||
function purgeTables(): void {
|
function purgeTables(): void {
|
||||||
console.time('purgeTables')
|
console.time('purgeTables')
|
||||||
|
|
||||||
|
const tablesToPurge = [
|
||||||
|
'WorkOrderMilestones',
|
||||||
|
'WorkOrderComments',
|
||||||
|
'WorkOrderLots',
|
||||||
|
'WorkOrderLotOccupancies',
|
||||||
|
'WorkOrders',
|
||||||
|
'LotOccupancyTransactions',
|
||||||
|
'LotOccupancyFees',
|
||||||
|
'LotOccupancyFields',
|
||||||
|
'LotOccupancyComments',
|
||||||
|
'LotOccupancyOccupants',
|
||||||
|
'LotOccupancies',
|
||||||
|
'LotFields',
|
||||||
|
'LotComments',
|
||||||
|
'Lots'
|
||||||
|
]
|
||||||
|
|
||||||
const database = sqlite(databasePath)
|
const database = sqlite(databasePath)
|
||||||
database.prepare('delete from WorkOrderMilestones').run()
|
|
||||||
database.prepare('delete from WorkOrderComments').run()
|
for (const tableName of tablesToPurge) {
|
||||||
database.prepare('delete from WorkOrderLots').run()
|
database.prepare(`delete from ${tableName}`).run()
|
||||||
database.prepare('delete from WorkOrderLotOccupancies').run()
|
|
||||||
database.prepare('delete from WorkOrders').run()
|
|
||||||
database.prepare('delete from LotOccupancyTransactions').run()
|
|
||||||
database.prepare('delete from LotOccupancyFees').run()
|
|
||||||
database.prepare('delete from LotOccupancyFields').run()
|
|
||||||
database.prepare('delete from LotOccupancyComments').run()
|
|
||||||
database.prepare('delete from LotOccupancyOccupants').run()
|
|
||||||
database.prepare('delete from LotOccupancies').run()
|
|
||||||
database.prepare('delete from LotFields').run()
|
|
||||||
database.prepare('delete from LotComments').run()
|
|
||||||
database.prepare('delete from Lots').run()
|
|
||||||
database
|
database
|
||||||
.prepare(
|
.prepare('delete from sqlite_sequence where name = ?')
|
||||||
"delete from sqlite_sequence where name in ('Lots', 'LotComments', 'LotOccupancies', 'LotOccupancyComments', 'WorkOrders', 'WorkOrderComments', 'WorkOrderMilestones')"
|
.run(tableName)
|
||||||
)
|
}
|
||||||
.run()
|
|
||||||
database.close()
|
database.close()
|
||||||
|
|
||||||
console.timeEnd('purgeTables')
|
console.timeEnd('purgeTables')
|
||||||
|
|
@ -329,7 +335,7 @@ async function getMap(dataRow: { cemetery: string }): Promise<recordTypes.Map> {
|
||||||
user
|
user
|
||||||
)
|
)
|
||||||
|
|
||||||
map = await getMapFromDatabase(mapId) as recordTypes.Map
|
map = (await getMapFromDatabase(mapId)) as recordTypes.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
mapCache.set(mapCacheKey, map)
|
mapCache.set(mapCacheKey, map)
|
||||||
|
|
@ -513,7 +519,8 @@ async function importFromMasterCSV(): Promise<void> {
|
||||||
lotOccupancyId: preneedLotOccupancyId,
|
lotOccupancyId: preneedLotOccupancyId,
|
||||||
lotOccupancyCommentDateString: preneedOccupancyStartDateString,
|
lotOccupancyCommentDateString: preneedOccupancyStartDateString,
|
||||||
lotOccupancyCommentTimeString: '00:00',
|
lotOccupancyCommentTimeString: '00:00',
|
||||||
lotOccupancyComment: 'Imported Contract #' + masterRow.CM_WORK_ORDER
|
lotOccupancyComment:
|
||||||
|
'Imported Contract #' + masterRow.CM_WORK_ORDER
|
||||||
},
|
},
|
||||||
user
|
user
|
||||||
)
|
)
|
||||||
|
|
@ -780,7 +787,8 @@ async function importFromMasterCSV(): Promise<void> {
|
||||||
lotOccupancyId: deceasedLotOccupancyId,
|
lotOccupancyId: deceasedLotOccupancyId,
|
||||||
lotOccupancyCommentDateString: deceasedOccupancyStartDateString,
|
lotOccupancyCommentDateString: deceasedOccupancyStartDateString,
|
||||||
lotOccupancyCommentTimeString: '00:00',
|
lotOccupancyCommentTimeString: '00:00',
|
||||||
lotOccupancyComment: 'Imported Contract #' + masterRow.CM_WORK_ORDER
|
lotOccupancyComment:
|
||||||
|
'Imported Contract #' + masterRow.CM_WORK_ORDER
|
||||||
},
|
},
|
||||||
user
|
user
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,9 @@ async function importMaps() {
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
pool.close();
|
if (pool !== undefined) {
|
||||||
|
await pool.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,21 @@ import * as sql from '@cityssm/mssql-multi-pool'
|
||||||
import { soMSSQL } from './config.js'
|
import { soMSSQL } from './config.js'
|
||||||
import type * as sqlTypes from 'mssql'
|
import type * as sqlTypes from 'mssql'
|
||||||
|
|
||||||
|
interface MapLayer {
|
||||||
|
mapId: string
|
||||||
|
mapName: string
|
||||||
|
layerId: string
|
||||||
|
layerName: string
|
||||||
|
layerImage: string
|
||||||
|
}
|
||||||
|
|
||||||
async function importMaps(): Promise<void> {
|
async function importMaps(): Promise<void> {
|
||||||
let pool: sqlTypes.ConnectionPool
|
let pool: sqlTypes.ConnectionPool | undefined
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pool = await sql.connect(soMSSQL)
|
pool = await sql.connect(soMSSQL)
|
||||||
|
|
||||||
const result = await pool.query(
|
const result: sqlTypes.IResult<MapLayer> = await pool.query(
|
||||||
'select m.ID as mapId, m.Name as mapName,' +
|
'select m.ID as mapId, m.Name as mapName,' +
|
||||||
' l.ID as layerId, l.Name as layerName, l.Image as layerImage' +
|
' l.ID as layerId, l.Name as layerName, l.Image as layerImage' +
|
||||||
' from Legacy_Maps m' +
|
' from Legacy_Maps m' +
|
||||||
|
|
@ -19,7 +27,7 @@ async function importMaps(): Promise<void> {
|
||||||
)
|
)
|
||||||
|
|
||||||
for (const layer of result.recordset) {
|
for (const layer of result.recordset) {
|
||||||
const imageBuffer: Buffer = layer.layerImage
|
const imageBuffer = layer.layerImage as unknown as Buffer
|
||||||
|
|
||||||
const fileName = `${layer.mapName} - ${layer.layerName} (${layer.mapId}, ${layer.layerId}).wmf`
|
const fileName = `${layer.mapName} - ${layer.layerName} (${layer.mapId}, ${layer.layerId}).wmf`
|
||||||
|
|
||||||
|
|
@ -33,7 +41,9 @@ async function importMaps(): Promise<void> {
|
||||||
// ignore
|
// ignore
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
pool.close()
|
if (pool !== undefined) {
|
||||||
|
await pool.close()
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue