Skip to content

Commit e19a159

Browse files
committed
🗃️ add sp name to moderation table
**Problem** The moderators have no idea from where a moderation is coming from. **Proposal** Add a `sp_name` column to the `moderation` table to track the source of the moderation.
1 parent 411b3dd commit e19a159

File tree

4 files changed

+55
-31
lines changed

4 files changed

+55
-31
lines changed

.changeset/huge-owls-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@proconnect-gouv/proconnect.identite.database": minor
3+
---
4+
5+
🗃️ Ajout de la colonne sp_name dans la table modération.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { ColumnDefinitions, MigrationBuilder } from "node-pg-migrate";
2+
3+
export const shorthands: ColumnDefinitions | undefined = undefined;
4+
5+
export async function up(pgm: MigrationBuilder): Promise<void> {
6+
await pgm.db.query(`
7+
ALTER TABLE moderations
8+
ADD COLUMN sp_name character varying;
9+
`);
10+
}
11+
12+
export async function down(pgm: MigrationBuilder): Promise<void> {
13+
await pgm.db.query(`
14+
ALTER TABLE moderations
15+
DROP COLUMN sp_name;
16+
`);
17+
}

packages/database/schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ CREATE TABLE "public"."moderations" (
255255
"comment" character varying,
256256
"moderated_by" character varying,
257257
"ticket_id" "text",
258-
"status" "text" DEFAULT 'unknown'::"text" NOT NULL
258+
"status" "text" DEFAULT 'unknown'::"text" NOT NULL,
259+
"sp_name" character varying
259260
);
260261

261262
--

packages/database/src/drizzle/schema.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -141,36 +141,6 @@ export const oidc_clients = pgTable("oidc_clients", {
141141
is_proconnect_federation: boolean().default(false).notNull(),
142142
});
143143

144-
export const moderations = pgTable(
145-
"moderations",
146-
{
147-
id: serial().primaryKey().notNull(),
148-
user_id: integer().notNull(),
149-
organization_id: integer().notNull(),
150-
type: varchar().notNull(),
151-
created_at: timestamp({ withTimezone: true, mode: "string" })
152-
.defaultNow()
153-
.notNull(),
154-
moderated_at: timestamp({ withTimezone: true, mode: "string" }),
155-
comment: varchar(),
156-
moderated_by: varchar(),
157-
ticket_id: text(),
158-
status: text().default("unknown").notNull(),
159-
},
160-
(table) => [
161-
foreignKey({
162-
columns: [table.user_id],
163-
foreignColumns: [users.id],
164-
name: "moderations_user_id_fkey",
165-
}).onDelete("cascade"),
166-
foreignKey({
167-
columns: [table.organization_id],
168-
foreignColumns: [organizations.id],
169-
name: "moderations_organization_id_fkey",
170-
}).onDelete("cascade"),
171-
],
172-
);
173-
174144
export const email_deliverability_whitelist = pgTable(
175145
"email_deliverability_whitelist",
176146
{
@@ -290,6 +260,37 @@ export const users_oidc_clients = pgTable(
290260
],
291261
);
292262

263+
export const moderations = pgTable(
264+
"moderations",
265+
{
266+
id: serial().primaryKey().notNull(),
267+
user_id: integer().notNull(),
268+
organization_id: integer().notNull(),
269+
type: varchar().notNull(),
270+
created_at: timestamp({ withTimezone: true, mode: "string" })
271+
.defaultNow()
272+
.notNull(),
273+
moderated_at: timestamp({ withTimezone: true, mode: "string" }),
274+
comment: varchar(),
275+
moderated_by: varchar(),
276+
ticket_id: text(),
277+
status: text().default("unknown").notNull(),
278+
sp_name: varchar(),
279+
},
280+
(table) => [
281+
foreignKey({
282+
columns: [table.user_id],
283+
foreignColumns: [users.id],
284+
name: "moderations_user_id_fkey",
285+
}).onDelete("cascade"),
286+
foreignKey({
287+
columns: [table.organization_id],
288+
foreignColumns: [organizations.id],
289+
name: "moderations_organization_id_fkey",
290+
}).onDelete("cascade"),
291+
],
292+
);
293+
293294
export const users_organizations = pgTable(
294295
"users_organizations",
295296
{

0 commit comments

Comments
 (0)