migration files
This commit is contained in:
157
backend/migrations/20241124000001-create-users.js
Normal file
157
backend/migrations/20241124000001-create-users.js
Normal file
@@ -0,0 +1,157 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable("Users", {
|
||||
id: {
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
email: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
},
|
||||
password: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
firstName: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
lastName: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
phone: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
authProvider: {
|
||||
type: Sequelize.ENUM("local", "google"),
|
||||
defaultValue: "local",
|
||||
},
|
||||
providerId: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
address1: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
address2: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
city: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
state: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
zipCode: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
country: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
profileImage: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
isVerified: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
verificationToken: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
verificationTokenExpiry: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
verifiedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
passwordResetToken: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
passwordResetTokenExpiry: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
defaultAvailableAfter: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: "09:00",
|
||||
},
|
||||
defaultAvailableBefore: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: "17:00",
|
||||
},
|
||||
defaultSpecifyTimesPerDay: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
defaultWeeklyTimes: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
sunday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
monday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
tuesday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
wednesday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
thursday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
friday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
saturday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
},
|
||||
},
|
||||
stripeConnectedAccountId: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
stripeCustomerId: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
loginAttempts: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0,
|
||||
},
|
||||
lockUntil: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
jwtVersion: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false,
|
||||
},
|
||||
role: {
|
||||
type: Sequelize.ENUM("user", "admin"),
|
||||
defaultValue: "user",
|
||||
allowNull: false,
|
||||
},
|
||||
itemRequestNotificationRadius: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 10,
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
// Add indexes
|
||||
await queryInterface.addIndex("Users", ["email"], { unique: true });
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable("Users");
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable("AlphaInvitations", {
|
||||
id: {
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
code: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
},
|
||||
email: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.ENUM("pending", "active", "revoked"),
|
||||
defaultValue: "pending",
|
||||
},
|
||||
usedBy: {
|
||||
type: Sequelize.UUID,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: "Users",
|
||||
key: "id",
|
||||
},
|
||||
onUpdate: "CASCADE",
|
||||
onDelete: "SET NULL",
|
||||
},
|
||||
usedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
// Add indexes
|
||||
await queryInterface.addIndex("AlphaInvitations", ["code"], {
|
||||
unique: true,
|
||||
});
|
||||
await queryInterface.addIndex("AlphaInvitations", ["email"]);
|
||||
await queryInterface.addIndex("AlphaInvitations", ["status"]);
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable("AlphaInvitations");
|
||||
},
|
||||
};
|
||||
168
backend/migrations/20241124000003-create-items.js
Normal file
168
backend/migrations/20241124000003-create-items.js
Normal file
@@ -0,0 +1,168 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable("Items", {
|
||||
id: {
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
pickUpAvailable: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
localDeliveryAvailable: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
localDeliveryRadius: {
|
||||
type: Sequelize.INTEGER,
|
||||
},
|
||||
shippingAvailable: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
inPlaceUseAvailable: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
pricePerHour: {
|
||||
type: Sequelize.DECIMAL(10, 2),
|
||||
},
|
||||
pricePerDay: {
|
||||
type: Sequelize.DECIMAL(10, 2),
|
||||
},
|
||||
pricePerWeek: {
|
||||
type: Sequelize.DECIMAL(10, 2),
|
||||
},
|
||||
pricePerMonth: {
|
||||
type: Sequelize.DECIMAL(10, 2),
|
||||
},
|
||||
replacementCost: {
|
||||
type: Sequelize.DECIMAL(10, 2),
|
||||
allowNull: false,
|
||||
},
|
||||
address1: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
address2: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
city: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
state: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
zipCode: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
country: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
latitude: {
|
||||
type: Sequelize.DECIMAL(10, 8),
|
||||
},
|
||||
longitude: {
|
||||
type: Sequelize.DECIMAL(11, 8),
|
||||
},
|
||||
images: {
|
||||
type: Sequelize.ARRAY(Sequelize.STRING),
|
||||
defaultValue: [],
|
||||
},
|
||||
isAvailable: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: true,
|
||||
},
|
||||
rules: {
|
||||
type: Sequelize.TEXT,
|
||||
},
|
||||
availableAfter: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: "09:00",
|
||||
},
|
||||
availableBefore: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: "17:00",
|
||||
},
|
||||
specifyTimesPerDay: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
weeklyTimes: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
sunday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
monday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
tuesday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
wednesday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
thursday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
friday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
saturday: { availableAfter: "09:00", availableBefore: "17:00" },
|
||||
},
|
||||
},
|
||||
ownerId: {
|
||||
type: Sequelize.UUID,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: "Users",
|
||||
key: "id",
|
||||
},
|
||||
onUpdate: "CASCADE",
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
isDeleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
deletedBy: {
|
||||
type: Sequelize.UUID,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: "Users",
|
||||
key: "id",
|
||||
},
|
||||
onUpdate: "CASCADE",
|
||||
onDelete: "SET NULL",
|
||||
},
|
||||
deletedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
deletionReason: {
|
||||
type: Sequelize.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
// Add indexes
|
||||
await queryInterface.addIndex("Items", ["ownerId"]);
|
||||
await queryInterface.addIndex("Items", ["isAvailable"]);
|
||||
await queryInterface.addIndex("Items", ["isDeleted"]);
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable("Items");
|
||||
},
|
||||
};
|
||||
72
backend/migrations/20241124000004-create-user-addresses.js
Normal file
72
backend/migrations/20241124000004-create-user-addresses.js
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable("UserAddresses", {
|
||||
id: {
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: Sequelize.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
userId: {
|
||||
type: Sequelize.UUID,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: "Users",
|
||||
key: "id",
|
||||
},
|
||||
onUpdate: "CASCADE",
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
address1: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
address2: {
|
||||
type: Sequelize.STRING,
|
||||
},
|
||||
city: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
state: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
zipCode: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
country: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: "US",
|
||||
},
|
||||
latitude: {
|
||||
type: Sequelize.DECIMAL(10, 8),
|
||||
},
|
||||
longitude: {
|
||||
type: Sequelize.DECIMAL(11, 8),
|
||||
},
|
||||
isPrimary: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
createdAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
// Add indexes
|
||||
await queryInterface.addIndex("UserAddresses", ["userId"]);
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable("UserAddresses");
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user