-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate old db #1053
base: main
Are you sure you want to change the base?
Deprecate old db #1053
Changes from all commits
8bfaa50
eb55b80
455beb5
58c8ae3
db89ee2
8e8f384
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import fs from 'fs'; | |
|
||
import { validateTime } from './time-math.js'; | ||
import { generateKey } from './date-db-formatter.js'; | ||
import { assert } from 'console'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to keep all external imports at the top of the file, and local imports below |
||
|
||
/** | ||
* Returns the database (only flexible calendar entries) as an array of: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can also remove the "flexible" comments and name functions now that the other doesn't exist anymore |
||
|
@@ -76,8 +77,7 @@ function _validateDate(dateStr) | |
|
||
function validEntry(entry) | ||
{ | ||
// TODO: 'regular' is still here while we allow importing old DB data. Please remove on the next release. | ||
if (entry.hasOwnProperty('type') && ['regular', 'waived', 'flexible'].indexOf(entry.type) !== -1) | ||
if (entry.hasOwnProperty('type') && ['waived', 'flexible'].indexOf(entry.type) !== -1) | ||
{ | ||
const validatedDate = entry.hasOwnProperty('date') && _validateDate(entry.date); | ||
let hasExpectedProperties; | ||
|
@@ -106,20 +106,6 @@ function validEntry(entry) | |
return false; | ||
} | ||
|
||
function mergeOldStoreDataIntoFlexibleStore(flexibleEntry, oldStoreHours) | ||
{ | ||
let index = 0; | ||
for (const hour of flexibleEntry.values) | ||
{ | ||
if (oldStoreHours > hour) | ||
{ | ||
index++; | ||
} | ||
} | ||
flexibleEntry.values.splice(index, 0, oldStoreHours); | ||
return flexibleEntry; | ||
} | ||
|
||
function importDatabaseFromFile(filename) | ||
{ | ||
const flexibleStore = new Store({name: 'flexible-store'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise this doesn't need to be called flexibleStore anymore |
||
|
@@ -144,26 +130,12 @@ function importDatabaseFromFile(filename) | |
} | ||
else | ||
{ | ||
assert(entry.type === 'flexible'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we write something on the test that hit this assert? |
||
const [year, month, day] = entry.date.split('-'); | ||
//The main database uses a JS-based month index (0-11) | ||
//So we need to adjust it from human month index (1-12) | ||
const date = generateKey(year, (parseInt(month) - 1), day); | ||
if (entry.type === 'flexible') | ||
{ | ||
flexibleEntries[date] = {values: entry.values}; | ||
} | ||
else if (entry.type === 'regular') | ||
{ | ||
// TODO: 'regular' is still here while we allow importing old DB data. Please remove on the next release. | ||
const [/*event*/, key] = entry.data.split('-'); | ||
if (['begin', 'end'].indexOf(key) !== -1) | ||
{ | ||
let currentFlexibleEntry = flexibleEntries[date]; | ||
if (currentFlexibleEntry === undefined) | ||
currentFlexibleEntry = { values: [] }; | ||
flexibleEntries[date] = mergeOldStoreDataIntoFlexibleStore(currentFlexibleEntry, entry.hours); | ||
} | ||
} | ||
flexibleEntries[date] = {values: entry.values}; | ||
} | ||
} | ||
|
||
|
@@ -182,47 +154,8 @@ function importDatabaseFromFile(filename) | |
return {'result': true}; | ||
} | ||
|
||
function migrateFixedDbToFlexible() | ||
{ | ||
const store = new Store(); | ||
const flexibleStore = new Store({name: 'flexible-store'}); | ||
flexibleStore.clear(); | ||
const regularEntryArray = []; | ||
for (const entry of store) | ||
{ | ||
const key = entry[0]; | ||
const value = entry[1]; | ||
|
||
const [year, month, day, /*stage*/, step] = key.split('-'); | ||
if (['begin', 'end'].indexOf(step) !== -1) | ||
{ | ||
const date = generateKey(year, month, day); | ||
if (regularEntryArray[date] === undefined) | ||
{ | ||
regularEntryArray[date] = { values: []}; | ||
} | ||
regularEntryArray[date].values.push(value); | ||
} | ||
} | ||
try | ||
{ | ||
for (const key of Object.keys(regularEntryArray)) | ||
{ | ||
regularEntryArray[key].values.sort(); | ||
flexibleStore.set(key, regularEntryArray[key]); | ||
} | ||
} | ||
catch (err) | ||
{ | ||
console.log(err); | ||
return {'result': false, 'err': err}; | ||
} | ||
return {'result': true, 'err': ''}; | ||
} | ||
|
||
module.exports = { | ||
exportDatabaseToFile, | ||
importDatabaseFromFile, | ||
migrateFixedDbToFlexible, | ||
validEntry, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be in a separate pr/commit?