-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from Carifio24/stage-states
Add infrastructure for stage states
- Loading branch information
Showing
5 changed files
with
156 additions
and
9 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
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Sequelize, DataTypes, Model, InferAttributes, InferCreationAttributes, CreationOptional } from "sequelize"; | ||
import { Story } from "./story"; | ||
import { Student } from "./student"; | ||
|
||
export class StageState extends Model<InferAttributes<StageState>, InferCreationAttributes<StageState>> { | ||
declare student_id: CreationOptional<number>; | ||
declare story_name: string; | ||
declare stage_name: string; | ||
declare state: JSON; | ||
declare last_modified: CreationOptional<Date>; | ||
} | ||
|
||
export function initializeStageStateModel(sequelize: Sequelize) { | ||
StageState.init({ | ||
student_id: { | ||
type: DataTypes.INTEGER.UNSIGNED, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: Student, | ||
key: "id" | ||
} | ||
}, | ||
story_name: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: Story, | ||
key: "name" | ||
} | ||
}, | ||
stage_name: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
primaryKey: true, | ||
}, | ||
state: { | ||
type: DataTypes.JSON, | ||
allowNull: false | ||
}, | ||
last_modified: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP") | ||
} | ||
}, { | ||
sequelize, | ||
engine: "InnoDB" | ||
}); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE TABLE StageStates ( | ||
student_id int(11) UNSIGNED NOT NULL, | ||
story_name varchar(50) NOT NULL, | ||
stage_name varchar(50) NOT NULL, | ||
state JSON NOT NULL, | ||
last_modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
ON UPDATE CURRENT_TIMESTAMP, | ||
|
||
PRIMARY KEY(student_id, story_name, stage_name), | ||
INDEX(student_id), | ||
INDEX(story_name), | ||
INDEX(stage_name), | ||
FOREIGN KEY(student_id) | ||
REFERENCES Students(id) | ||
ON UPDATE CASCADE | ||
ON DELETE CASCADE, | ||
FOREIGN KEY(story_name) | ||
REFERENCES Stories(name) | ||
ON UPDATE CASCADE | ||
ON DELETE CASCADE | ||
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci PACK_KEYS=0; |