Parcourir la source

refactor: Add generated user hasPassword field

Owen Diffey il y a 1 mois
Parent
commit
915ac498a3

+ 8 - 0
backend/src/modules/DataModule/migrations/1725485641-create-users-table.ts

@@ -125,6 +125,14 @@ export const up = async ({
 		createdAt: DataTypes.DATE,
 		updatedAt: DataTypes.DATE
 	});
+
+	await sequelize.query(
+		"ALTER TABLE users " +
+			'ADD COLUMN "hasPassword" ' +
+			"BOOLEAN GENERATED ALWAYS AS " +
+			'("password" IS NOT NULL) ' +
+			"STORED"
+	);
 };
 
 export const down = async ({

+ 4 - 0
backend/src/modules/DataModule/models/User.ts

@@ -274,6 +274,10 @@ export const schema = {
 	},
 	createdAt: DataTypes.DATE,
 	updatedAt: DataTypes.DATE,
+	hasPassword: {
+		type: DataTypes.BOOLEAN,
+		readonly: true
+	},
 	_name: {
 		type: DataTypes.VIRTUAL,
 		get() {