Преглед на файлове

refactor: Add generated user hasPassword field

Owen Diffey преди 4 седмици
родител
ревизия
915ac498a3
променени са 2 файла, в които са добавени 12 реда и са изтрити 0 реда
  1. 8 0
      backend/src/modules/DataModule/migrations/1725485641-create-users-table.ts
  2. 4 0
      backend/src/modules/DataModule/models/User.ts

+ 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() {