-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
150 additions
and
35 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,29 @@ | ||
"use strict"; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.query(` | ||
CREATE TABLE IF NOT EXISTS mano."UserLog" ( | ||
_id uuid NOT NULL, | ||
"createdAt" timestamp with time zone NOT NULL, | ||
"updatedAt" timestamp with time zone NOT NULL, | ||
organisation uuid, | ||
"user" uuid, | ||
platform text, | ||
action text, | ||
"debugApp" jsonb, | ||
"debugDashboard" jsonb, | ||
PRIMARY KEY (_id), | ||
CONSTRAINT "UserLog_organisation_fkey" FOREIGN KEY (organisation) REFERENCES mano."Organisation"(_id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE, | ||
CONSTRAINT "UserLog_user_fkey" FOREIGN KEY ("user") REFERENCES mano."User"(_id) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE | ||
); | ||
CREATE INDEX "UserLog_organisation_idx" ON mano."UserLog" USING btree (organisation); | ||
CREATE INDEX "UserLog_user_idx" ON mano."UserLog" USING btree ("user"); | ||
`); | ||
}, | ||
|
||
async down() { | ||
// Qui fait des down, et pourquoi ? | ||
}, | ||
}; |
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,27 @@ | ||
Pour ajouter une migration, faites | ||
|
||
```bash | ||
npx sequelize-cli migration:generate --name mon-fichier | ||
``` | ||
|
||
Puis modifiez le fichier créé dans `api/src/db/migrations/` pour ajouter les instructions SQL nécessaires. | ||
|
||
Par exemple | ||
|
||
``` | ||
"use strict"; | ||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.sequelize.query(` | ||
ALTER TABLE "mano"."User" | ||
ADD COLUMN IF NOT EXISTS "phone" text; | ||
`); | ||
}, | ||
async down() { | ||
// Qui fait des down, et pourquoi ? | ||
}, | ||
}; | ||
``` |
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,24 @@ | ||
const { Model, Deferrable } = require("sequelize"); | ||
|
||
module.exports = (sequelize, DataTypes) => { | ||
const schema = { | ||
_id: { type: DataTypes.UUID, allowNull: false, defaultValue: DataTypes.UUIDV4, primaryKey: true }, | ||
organisation: { type: DataTypes.UUID, references: { model: "Organisation", key: "_id", deferrable: Deferrable.INITIALLY_IMMEDIATE } }, | ||
user: { type: DataTypes.UUID, references: { model: "User", key: "_id", deferrable: Deferrable.INITIALLY_IMMEDIATE } }, | ||
platform: DataTypes.TEXT, // dashboard, app | ||
action: DataTypes.TEXT, // login, logout, change-encryption-key | ||
debugApp: DataTypes.JSONB, | ||
debugDashboard: DataTypes.JSONB, | ||
}; | ||
|
||
class UserLog extends Model { | ||
static associate({ Organisation, User }) { | ||
Organisation.hasMany(UserLog, { foreignKey: { type: DataTypes.UUID, name: "organisation", field: "organisation" } }); | ||
User.hasMany(UserLog, { foreignKey: { type: DataTypes.UUID, name: "organisation", field: "organisation" } }); | ||
} | ||
} | ||
|
||
UserLog.init(schema, { sequelize, modelName: "UserLog", freezeTableName: true, timestamps: true }); | ||
|
||
return UserLog; | ||
}; |