@churchsoln/dbms 1.0.44 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, DataTypes) => {
5
+ // Remove the old foreign key constraint
6
+ await queryInterface.removeConstraint(
7
+ "GroupMembers",
8
+ "GroupMembers_UserId_Fkey"
9
+ );
10
+
11
+ // Remove the userId column
12
+ await queryInterface.removeColumn(
13
+ "GroupMembers",
14
+ "userId"
15
+ );
16
+
17
+ // Add the new memberId column
18
+ await queryInterface.addColumn(
19
+ "GroupMembers",
20
+ "memberId",
21
+ {
22
+ type: DataTypes.INTEGER,
23
+ allowNull: true
24
+ }
25
+ );
26
+
27
+ // Add the new foreign key constraint with memberId
28
+ await queryInterface.addConstraint("GroupMembers", {
29
+ fields: ["memberId"],
30
+ type: "foreign key",
31
+ name: "GroupMembers_MemberId_Fkey",
32
+ references: {
33
+ table: "Member",
34
+ field: "id",
35
+ },
36
+ onDelete: "cascade",
37
+ onUpdate: "cascade",
38
+ });
39
+ },
40
+
41
+ down: async (queryInterface, DataTypes) => {
42
+ // Remove the new foreign key constraint
43
+ await queryInterface.removeConstraint(
44
+ "GroupMembers",
45
+ "GroupMembers_MemberId_Fkey"
46
+ );
47
+
48
+ // Remove the memberId column
49
+ await queryInterface.removeColumn(
50
+ "GroupMembers",
51
+ "memberId"
52
+ );
53
+
54
+ // Add back the userId column
55
+ await queryInterface.addColumn(
56
+ "GroupMembers",
57
+ "userId",
58
+ {
59
+ type: DataTypes.INTEGER,
60
+ allowNull: true
61
+ }
62
+ );
63
+
64
+ // Restore the old foreign key constraint
65
+ await queryInterface.addConstraint("GroupMembers", {
66
+ fields: ["userId"],
67
+ type: "foreign key",
68
+ name: "GroupMembers_UserId_Fkey",
69
+ references: {
70
+ table: "User",
71
+ field: "id",
72
+ },
73
+ onDelete: "cascade",
74
+ onUpdate: "cascade",
75
+ });
76
+ }
77
+ };
@@ -3,10 +3,10 @@ module.exports = (sequelize, DataTypes) => {
3
3
  "GroupMembers",
4
4
  {
5
5
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
6
- userId: {
6
+ memberId: {
7
7
  type: DataTypes.INTEGER,
8
- set(userId) {
9
- this.setDataValue("userId", userId?.id || userId);
8
+ set(memberId) {
9
+ this.setDataValue("memberId", memberId?.id || memberId);
10
10
  },
11
11
  },
12
12
  groupId: {
@@ -41,9 +41,9 @@ module.exports = (sequelize, DataTypes) => {
41
41
  { freezeTableName: true, timestamps: false }
42
42
  );
43
43
  groupMembers.associate = function (models) {
44
- groupMembers.belongsTo(models.user, {
45
- foreignKey: "userId",
46
- as: "user",
44
+ groupMembers.belongsTo(models.member, {
45
+ foreignKey: "memberId",
46
+ as: "member",
47
47
  });
48
48
  groupMembers.belongsTo(models.group, {
49
49
  foreignKey: "groupId",
@@ -60,7 +60,7 @@ module.exports = (sequelize, DataTypes) => {
60
60
  };
61
61
  groupMembers.selectedFields = [
62
62
  "id",
63
- "userId",
63
+ "memberId",
64
64
  "groupId",
65
65
  "isAdmin",
66
66
  "status",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchsoln/dbms",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "prestart": "node db-setup.js",