-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
332 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
import { readFileSync } from "fs"; | ||
import sequelize from "./config/database.js"; | ||
import { KendoUIAppointment, KendoUIResource } from "./models/index.js"; | ||
|
||
async function setupDatabase() { | ||
// Wait for all models to synchronize with the database | ||
await sequelize.sync(); | ||
|
||
// Now add example data | ||
await addExampleData(); | ||
} | ||
|
||
async function addExampleData() { | ||
try { | ||
// Read and parse the JSON data | ||
const resourcesData = JSON.parse( | ||
readFileSync("./initialData/kendouiResources.json") | ||
); | ||
const appointmentsData = JSON.parse( | ||
readFileSync("./initialData/kendouiAppointments.json") | ||
); | ||
|
||
await sequelize.transaction(async (t) => { | ||
const resources = await KendoUIResource.bulkCreate(resourcesData, { | ||
transaction: t, | ||
}); | ||
const appointments = await KendoUIAppointment.bulkCreate( | ||
appointmentsData, | ||
{ transaction: t } | ||
); | ||
return { resources, appointments }; | ||
}); | ||
|
||
console.log( | ||
"resources and appointments added to database successfully." | ||
); | ||
} catch (error) { | ||
console.error("Failed to add data to database due to an error: ", error); | ||
} | ||
} | ||
|
||
import { readFileSync } from 'fs'; | ||
import sequelize from './config/database.js'; | ||
import { KendoUIAppointment, KendoUIResource } from './models/index.js'; | ||
|
||
async function setupDatabase() { | ||
// Wait for all models to synchronize with the database | ||
await sequelize.sync(); | ||
|
||
// Now add example data | ||
await addExampleData(); | ||
} | ||
|
||
async function addExampleData() { | ||
try { | ||
// Read and parse the JSON data | ||
const resourcesData = JSON.parse( | ||
readFileSync('./initialData/kendouiResources.json') | ||
); | ||
const appointmentsData = JSON.parse( | ||
readFileSync('./initialData/kendouiAppointments.json') | ||
); | ||
|
||
await sequelize.transaction(async(t) => { | ||
const resources = await KendoUIResource.bulkCreate(resourcesData, { | ||
transaction : t | ||
}); | ||
const appointments = await KendoUIAppointment.bulkCreate( | ||
appointmentsData, | ||
{ transaction : t } | ||
); | ||
return { resources, appointments }; | ||
}); | ||
|
||
console.log( | ||
'resources and appointments added to database successfully.' | ||
); | ||
} | ||
catch (error) { | ||
console.error('Failed to add data to database due to an error: ', error); | ||
} | ||
} | ||
|
||
setupDatabase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { Sequelize } from "sequelize"; | ||
|
||
const sequelize = new Sequelize({ | ||
dialect: "sqlite", | ||
storage: "./database.sqlite3", | ||
}); | ||
|
||
import { Sequelize } from 'sequelize'; | ||
|
||
const sequelize = new Sequelize({ | ||
dialect : 'sqlite', | ||
storage : './database.sqlite3' | ||
}); | ||
|
||
export default sequelize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,67 @@ | ||
import { DataTypes } from "sequelize"; | ||
import sequelize from "../config/database.js"; | ||
|
||
const KendoUIAppointment = sequelize.define( | ||
"KendoUIAppointment", | ||
{ | ||
meetingID: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
title: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
start: { | ||
type: DataTypes.DATE, | ||
defaultValue: null, | ||
}, | ||
end: { | ||
type: DataTypes.DATE, | ||
defaultValue: null, | ||
}, | ||
startTimezone: { | ||
type: DataTypes.STRING, | ||
}, | ||
endTimezone: { | ||
type: DataTypes.STRING, | ||
}, | ||
description: { | ||
type: DataTypes.STRING, | ||
}, | ||
recurrenceID: { | ||
type: DataTypes.STRING, | ||
}, | ||
recurrenceRule: { | ||
type: DataTypes.STRING, | ||
}, | ||
recurrenceException: { | ||
type: DataTypes.STRING, | ||
}, | ||
roomId: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "kendoui_resources", | ||
key: "value", | ||
}, | ||
onDelete: "CASCADE", // This will delete all appointments referencing the resource when it's deleted | ||
}, | ||
isAllDay: { | ||
type: DataTypes.BOOLEAN, | ||
defaultValue: false, | ||
}, | ||
}, | ||
{ | ||
tableName: "kendoui_appointments", | ||
timestamps: false, | ||
indexes: [ | ||
{ | ||
fields: ["start", "end"], | ||
}, | ||
], | ||
} | ||
); | ||
|
||
import { DataTypes } from 'sequelize'; | ||
import sequelize from '../config/database.js'; | ||
|
||
const KendoUIAppointment = sequelize.define( | ||
'KendoUIAppointment', | ||
{ | ||
meetingID : { | ||
type : DataTypes.INTEGER, | ||
primaryKey : true, | ||
autoIncrement : true | ||
}, | ||
title : { | ||
type : DataTypes.STRING, | ||
allowNull : false | ||
}, | ||
start : { | ||
type : DataTypes.DATE, | ||
defaultValue : null | ||
}, | ||
end : { | ||
type : DataTypes.DATE, | ||
defaultValue : null | ||
}, | ||
startTimezone : { | ||
type : DataTypes.STRING | ||
}, | ||
endTimezone : { | ||
type : DataTypes.STRING | ||
}, | ||
description : { | ||
type : DataTypes.STRING | ||
}, | ||
recurrenceID : { | ||
type : DataTypes.STRING | ||
}, | ||
recurrenceRule : { | ||
type : DataTypes.STRING | ||
}, | ||
recurrenceException : { | ||
type : DataTypes.STRING | ||
}, | ||
roomId : { | ||
type : DataTypes.INTEGER, | ||
allowNull : false, | ||
references : { | ||
model : 'kendoui_resources', | ||
key : 'value' | ||
}, | ||
onDelete : 'CASCADE' // This will delete all appointments referencing the resource when it's deleted | ||
}, | ||
isAllDay : { | ||
type : DataTypes.BOOLEAN, | ||
defaultValue : false | ||
} | ||
}, | ||
{ | ||
tableName : 'kendoui_appointments', | ||
timestamps : false, | ||
indexes : [ | ||
{ | ||
fields : ['start', 'end'] | ||
} | ||
] | ||
} | ||
); | ||
|
||
export default KendoUIAppointment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { DataTypes } from "sequelize"; | ||
import sequelize from "../config/database.js"; | ||
|
||
const KendoUIResource = sequelize.define( | ||
"KendoUIResource", | ||
{ | ||
value: { | ||
type: DataTypes.INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
text: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
}, | ||
color: { | ||
type: DataTypes.STRING, | ||
defaultValue: null, | ||
}, | ||
}, | ||
{ | ||
tableName: "kendoui_resources", | ||
timestamps: false, | ||
} | ||
); | ||
|
||
export default KendoUIResource; | ||
import { DataTypes } from 'sequelize'; | ||
import sequelize from '../config/database.js'; | ||
|
||
const KendoUIResource = sequelize.define( | ||
'KendoUIResource', | ||
{ | ||
value : { | ||
type : DataTypes.INTEGER, | ||
primaryKey : true, | ||
autoIncrement : true | ||
}, | ||
text : { | ||
type : DataTypes.STRING, | ||
allowNull : false | ||
}, | ||
color : { | ||
type : DataTypes.STRING, | ||
defaultValue : null | ||
} | ||
}, | ||
{ | ||
tableName : 'kendoui_resources', | ||
timestamps : false | ||
} | ||
); | ||
|
||
export default KendoUIResource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import KendoUIResource from "./KendoUIResource.js"; | ||
import KendoUIAppointment from "./KendoUIAppointment.js"; | ||
|
||
export { | ||
KendoUIResource, | ||
KendoUIAppointment, | ||
}; | ||
import KendoUIResource from './KendoUIResource.js'; | ||
import KendoUIAppointment from './KendoUIAppointment.js'; | ||
|
||
export { | ||
KendoUIResource, | ||
KendoUIAppointment | ||
}; |
Oops, something went wrong.