Skip to content

Commit

Permalink
Merge pull request #493 from bluewave-labs/rewrite-migrations
Browse files Browse the repository at this point in the history
Rewrite migrations
  • Loading branch information
erenfn authored Jan 17, 2025
2 parents fbcd7c2 + 9ae38b9 commit 5c31027
Show file tree
Hide file tree
Showing 33 changed files with 775 additions and 806 deletions.
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ ALLOWED_IPS=127.0.0.1, 11.22.33.44, 11.22.33.45, 11.22.33.46, 192.168.65.1
FRONTEND_URL=http://localhost:4173/

# JWT secret for running npm run dev in backend folder locally
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
74 changes: 74 additions & 0 deletions backend/migrations/0000-1.0-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

const settings = require('./../config/settings');

const TABLE_NAME = 'users'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING(50),
allowNull: false,
},
surname: {
type: Sequelize.STRING(50),
allowNull: true,
},
email: {
type: Sequelize.STRING(100),
allowNull: false,
unique: true,
},
password: {
type: Sequelize.STRING(100),
allowNull: false,
},
role: {
type: Sequelize.ENUM,
values: settings.user.roleEnum,
defaultValue: settings.user.role.admin,
allowNull: false,
},
picture:{
type: Sequelize.TEXT,
allowNull: true,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},
}, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
68 changes: 68 additions & 0 deletions backend/migrations/0001-1.0-helperlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const TABLE_NAME = 'helper_link'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
headerBackgroundColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#F8F9F8'
},
linkFontColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#344054'
},
iconColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue: '#7F56D9'
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
}
}, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
68 changes: 68 additions & 0 deletions backend/migrations/0003-1.0-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const TABLE_NAME = 'link'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
url: {
type: Sequelize.STRING(255),
allowNull: false,
},
order: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 1,
},
target: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: true,
},
helperId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: "helper_link",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
}, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
67 changes: 67 additions & 0 deletions backend/migrations/0004-1.0-tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

const TABLE_NAME = 'tokens'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
token: {
type: Sequelize.STRING(500),
allowNull: false,
},
userId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
type: {
type: Sequelize.STRING(10),
allowNull: false,
},
expiresAt: {
type: Sequelize.DATE,
allowNull: true,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},

}, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
83 changes: 83 additions & 0 deletions backend/migrations/0005-1.0-banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

const TABLE_NAME = 'banners'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
closeButtonAction: {
type: Sequelize.STRING(255),
allowNull: false
},
repetitionType: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: 'show only once'
},
position: {
type: Sequelize.STRING(255),
allowNull: false
},
url: {
type: Sequelize.STRING(255),
allowNull: true
},
fontColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
backgroundColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
bannerText: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: ""
},
actionUrl: {
type: Sequelize.STRING(255),
allowNull: true
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
}
}, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.dropTable(TABLE_NAME, { transaction });
// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
Loading

0 comments on commit 5c31027

Please sign in to comment.