-
Notifications
You must be signed in to change notification settings - Fork 0
DDL operation #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 22 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
e87534b
user-authentication
rifasania 4b87b16
fixing:user-authentication
rifasania de17149
implement linter and prettier
rifasania cd1e3b7
fixing2:user-authentication
rifasania e52dd01
fixing3:user-authentication
rifasania fbd294b
Test husky pre-commit
rifasania 0ca604b
test husky pre-commmit
rifasania 22bd248
test husky pre-committt
rifasania ddb4707
test prettier jebal
rifasania f3169a7
test linter prettier
rifasania 52c8390
pre-commit linter prettier done
rifasania 0da64bc
pre-commit linter and prettier
rifasania bff3aa8
cek
rifasania a3d5f3e
fixed all
rifasania 17bcfc1
fixed error
rifasania 1af47b5
fixed:all
rifasania 8fc9dea
ddl-operation
rifasania 85e5f2a
resolve conflict pt.2
rifasania dfbc3b3
finished resolve conflict
rifasania 92ce8e5
fixing:ddl-operation
rifasania 0404e2e
fixed ddl operation
rifasania a8fb6e7
fixing3:ddl-operation
rifasania 5f946f2
fixed code + testing
rifasania d3bae85
fixed github actions
rifasania d83a0c4
fixed github action: jwt
rifasania 5ac8582
fixing:github action
rifasania 5e225e3
fixing:github-action:add-sync
rifasania da489c3
fixing:github-action:fix-postgres
rifasania 25582f8
fixing:github-action:debug-yaml
rifasania a62d103
test
rifasania 560713c
test2
rifasania 3b94935
rollback
rifasania 9cec989
test4
rifasania 6eb0509
test5
rifasania 723f114
md
rifasania 66c0890
test7
rifasania 3463452
test8
rifasania 06c7d15
url
rifasania 986cb20
tolong
rifasania 2e209e1
fixed:github-action:add-migrations
rifasania fb20f56
fixed:testing
rifasania e7071ea
fixed:refactor-function-test
rifasania 5f0783c
add-testing
rifasania e0f11f6
finished-ddl-operation
rifasania File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { Request, Response } from 'express'; | ||
| import { sequelize } from '../config/database'; | ||
| import { successResponse, errorResponse } from '../utils/response'; | ||
| import { Operations } from '../types/ddl'; | ||
| import { | ||
| CreateTable, | ||
| CreateColumn, | ||
| AlterTable, | ||
| AlterColumn, | ||
| DropColumn, | ||
| DropTable, | ||
| } from '../operations/ddl'; | ||
|
|
||
| export const migrate = async (req: Request, res: Response) => { | ||
| const { operations }: { operations: Operations[] } = req.body; | ||
| if (!operations || !Array.isArray(operations)) | ||
| return errorResponse(res, 'Invalid payload structure', 400); | ||
|
|
||
| const transaction = await sequelize.transaction(); | ||
|
|
||
| try { | ||
| for (const { operation, resource, migration } of operations) { | ||
| const { name, table, column, from, to } = migration; | ||
|
|
||
| let finalColumnDefinition = {}; | ||
| if (column && typeof column === 'object' && 'definition' in column) { | ||
| finalColumnDefinition = (column as any).definition; | ||
| } | ||
|
|
||
| switch (`${operation}-${resource}`) { | ||
| case 'Create-Table': | ||
| await CreateTable.execute(name!, migration!, transaction); | ||
| break; | ||
| case 'Create-Column': | ||
| await CreateColumn.execute(table!, migration!, transaction); | ||
| break; | ||
| case 'Alter-Table': | ||
| await AlterTable.execute(from!, to!, transaction); | ||
| break; | ||
| case 'Alter-Column': | ||
| await AlterColumn.execute( | ||
| table!, | ||
| from!, | ||
| to!, | ||
| finalColumnDefinition, | ||
| transaction, | ||
| ); | ||
| break; | ||
| case 'Drop-Column': | ||
| await DropColumn.execute(table!, column!, transaction); | ||
| break; | ||
| case 'Drop-Table': | ||
| await DropTable.execute(name!, transaction); | ||
| break; | ||
| default: | ||
| throw new Error(`Unsupported operation: ${operation} on ${resource}`); | ||
| } | ||
| } | ||
|
|
||
| await transaction.commit(); | ||
| return successResponse(res, {}, 'DDL operations completed successfully'); | ||
| } catch (error: any) { | ||
| await transaction.rollback(); | ||
| return errorResponse(res, error.message, 500); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { QueryInterface, DataTypes, Sequelize } from 'sequelize'; | ||
|
|
||
| /** @type {import('sequelize-cli').Migration} */ | ||
| export default { | ||
| async up(queryInterface: QueryInterface, sequelize: Sequelize) { | ||
| await queryInterface.sequelize.query( | ||
| 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";', | ||
| ); | ||
|
|
||
| await queryInterface.createTable('users', { | ||
| id: { | ||
| allowNull: false, | ||
| primaryKey: true, | ||
| type: DataTypes.UUID, | ||
| defaultValue: sequelize.literal('uuid_generate_v4()'), | ||
| }, | ||
| name: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| }, | ||
| email: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| unique: true, | ||
| }, | ||
| password: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| }, | ||
| apikey: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| unique: true, | ||
| }, | ||
| created_at: { | ||
| allowNull: false, | ||
| type: DataTypes.DATE, | ||
| defaultValue: sequelize.literal('CURRENT_TIMESTAMP'), | ||
| }, | ||
| updated_at: { | ||
| allowNull: false, | ||
| type: DataTypes.DATE, | ||
| defaultValue: sequelize.literal('CURRENT_TIMESTAMP'), | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| async down(queryInterface: QueryInterface) { | ||
| await queryInterface.dropTable('users'); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { Model, DataTypes } from 'sequelize'; | ||
| import { sequelize } from '../config/database'; | ||
| import MetadataTable from './metadata-table'; | ||
|
|
||
| class MetadataColumn extends Model { | ||
| public id!: string; | ||
| public table_id!: string; | ||
| public column_name!: string; | ||
| public data_type!: string; | ||
| public is_primary!: boolean; | ||
| public is_nullable!: boolean; | ||
| public is_unique!: boolean; | ||
| public readonly createdAt!: Date; | ||
| public readonly updatedAt!: Date; | ||
| } | ||
|
|
||
| MetadataColumn.init( | ||
| { | ||
| id: { | ||
| type: DataTypes.UUID, | ||
| defaultValue: DataTypes.UUIDV4, | ||
| primaryKey: true, | ||
| }, | ||
| table_id: { | ||
|
rifasania marked this conversation as resolved.
|
||
| type: DataTypes.UUID, | ||
| allowNull: false, | ||
| references: { | ||
| model: MetadataTable, | ||
| key: 'id', | ||
| }, | ||
| onDelete: 'CASCADE', | ||
| }, | ||
| column_name: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| }, | ||
| data_type: { | ||
| type: DataTypes.STRING, | ||
| allowNull: false, | ||
| }, | ||
| is_primary: { | ||
| type: DataTypes.BOOLEAN, | ||
| defaultValue: false, | ||
| }, | ||
| is_nullable: { | ||
| type: DataTypes.BOOLEAN, | ||
| defaultValue: true, | ||
| }, | ||
| is_unique: { | ||
| type: DataTypes.BOOLEAN, | ||
| defaultValue: false, | ||
| }, | ||
| created_at: { | ||
| type: DataTypes.DATE, | ||
| defaultValue: DataTypes.NOW, | ||
| }, | ||
| updated_at: { | ||
| type: DataTypes.DATE, | ||
| defaultValue: DataTypes.NOW, | ||
| }, | ||
| }, | ||
| { | ||
| sequelize, | ||
| modelName: 'MetadataColumn', | ||
| tableName: 'metadata_column', | ||
| timestamps: true, | ||
| underscored: true, | ||
| }, | ||
| ); | ||
|
|
||
| MetadataColumn.belongsTo(MetadataTable, { | ||
| foreignKey: 'table_id', | ||
| onDelete: 'CASCADE', | ||
| }); | ||
|
|
||
| export default MetadataColumn; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.