Giter VIP home page Giter VIP logo

mad-migration's Introduction

Project logo

Database Migration Tool

Status GitHub Issues GitHub Pull Requests License

๐Ÿง About

The Database Migration Tool was designed for those looking to migrate their data from one database to another. Additionally type casting is supported if you need to change column type in new version. Our main goal is to make data migration possible between different database servers. For example mysql, postgresql.

Currently only mysql and postgresql is supported. Future planning is to support migration from/to other databases.


Documentation: Documentation

๐Ÿ Getting Started

Installing

pip install madmigration

Usage

madmigration -f migration_schema.yaml

Configuration

After installation you should define YAML file where configuration will be taken in order to apply data to target database. Yaml file with list and dictionaries may contain following structures:

alt text

Connection Config

  • SourceConfig is intented to be data from source database
  • DestinationConfig is intented to be transfered data to target database
version: 0.1.6
Configs:
  - SourceConfig:
       dbURI: "postgres://admin:[email protected]/oldDB"
  - DestinationConfig:
       dbURI: "mysql://admin:[email protected]/newDB"

migrationTables:
  - migrationTable:
      SourceTable:
        name: users
      DestinationTable:
        name: persons
        create: True

      MigrationColumns:
        - sourceColumn:
            name: id
          destinationColumn:
            name: id
            options:
              type_cast: bigint
              primary_key: true
              autoincrement: true

        - sourceColumn:
            name: name
          destinationColumn:
            name: fname
            options:
              type_cast: varchar
              length: 32
      
        - sourceColumn:
            name: surname
          destinationColumn:
            name: lname
            options:
              type_cast: varchar
              length: 32
              index: true

        - sourceColumn:
            name: age
          destinationColumn:
            name: age
            options:
              type_cast: int

        - sourceColumn:
            name: createdAT
          destinationColumn:
            name: created_at
            options:
              type_cast: datetime

        - sourceColumn:
            name: updatedAT
          destinationColumn:
            name: updated_at
            options:
              type_cast: datetime

Configs section

  • SourceConfig set the source database configurations
    • dbURI source database URI
  • DestinationConfig set the destination database configurations
    • dbURI destination database URI
Configs:
  - SourceConfig:
       dbURI: "postgres://root:[email protected]/oldDB"  # set source database uri
  - DestinationConfig:
       dbURI: "mysql://root:[email protected]/newDB"  # set destination database uri

migrationTables section

  • migrationTables in this configuration, you will write the source of the table that you have to migrate and the destination tables that will migrate the data.
    • migrationTable specify the source and destination table name
      • SourceTable information about source table
        • name source table name
      • DestinationTable information about destination table
        • name destination table name
        • create bool value. This parameter tells the program whether it should create a table or not. (default false)
migrationTables:
  - migrationTable:
      SourceTable:
        name: users
      DestinationTable:
        name: persons
        create: True

MigrationColumns section

  • MigrationColumns specify source and destination column
    • sourceColumn information about source column
      • name source column name
    • destinationColumn information about destination column
      • name destination column name
      • options column options
        • type_cast destination column type name varchar,integer etc. (when we convert data we use this parameter)
MigrationColumns:
  - sourceColumn:
      name: id
    destinationColumn:
      name: id
      options:
        type_cast: bigint
        primary_key: true
        autoincrement: true

If you want to create a foreign key you can specify it in the column parameters

- sourceColumn:
    name: USERID
  destinationColumn:
    name: user_id
    options:
      type_cast: uuid
      foreign_key:
        table_name: users
        column_name: id
        ondelete: CASCADE

You can split your .yaml files or import .json file into .yaml file.

You must create the main .yaml file and importing other files into main .yaml file.

main.yaml file

version: 1.1
Configs:
  - SourceConfig:
      dbURI: "mysql://admin:[email protected]/old"
  - DestinationConfig:
      dbURI: "postgresql://admin:[email protected]/new"

migrationTables:
  - migrationTable: !import company.yaml
  - migrationTable: !import op_cond.json

company.yaml file

SourceTable:
  name: company
DestinationTable:
  name: company
  create: true 

MigrationColumns:
  - sourceColumn:
      name: id
    destinationColumn: 
      name: id
      options:
        primary_key: true
        type_cast: uuid

  - sourceColumn:
      name: name
    destinationColumn:
      name: name
      options:
        length: 120
        type_cast: varchar
        nullable: false

  - sourceColumn:
      name: created
    destinationColumn:
      name: created
      options:
        type_cast: datetime
  - sourceColumn:
      name: updated
    destinationColumn:
      name: updated
      options:
        type_cast: datetime
        nullable: true

op_conds.json file

{
    "SourceTable": {
      "name": "operation_conditions"
    },
    "DestinationTable": {
      "name": "operation_conditions",
      "create": true
    },
    "MigrationColumns": [
      {
        "sourceColumn": {
          "name": "id"
        },
        "destinationColumn": {
          "name": "id",
          "options": {
            "primary_key": true,
            "type_cast": "uuid"
          }
        }
      },
      {
        "sourceColumn": {
          "name": "interest"
        },
        "destinationColumn": {
          "name": "interest",
          "options": {
            "type_cast": "varchar",
            "length": 30,
            "nullable": false
          }
        }
      },
      {
        "sourceColumn": {
          "name": "FIFD"
        },
        "destinationColumn": {
          "name": "FIFD",
          "options": {
            "type_cast": "varchar",
            "length": 30,
            "nullable": false
          }
        }
      },
      {
        "sourceColumn": {
          "name": "comission"
        },
        "destinationColumn": {
          "name": "comission",
          "options": {
            "type_cast": "varchar",
            "length": 30,
            "nullable": false
          }
        }
      }
    ]
  }

See also the list of contributors who participated in this project.

Contributing

We are open to new ideas, additions. If you have any we would be happy to recieve and diccuss.

mad-migration's People

Contributors

aliyevh avatar dependabot[bot] avatar elnurhasan avatar maestro-1 avatar sabuhish avatar turall avatar turalpb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mad-migration's Issues

Handleing Exception

The custom exceptions should have to occur while migrating, the program should exit normally with raising it.

Convert data function

Convert data function
We have to convert data base on yaml Column Options before inserting data.

Describe the solution you'd like
Added DataTypeConvert class to convert data

Logging

for each important operation logging for console.

Tracking migration

Tracking migration progress ,store inserted data count, last record id, time and etc.

Table operation

Create class for table creation operations. Separately for each driver

mysql driver: type: string length error

In yaml if user specify in detinationColumn type String or VARCHAR table creation results with error. We have to add logic to detect this column type and specify column lenght.

In mad_migratiion i have added function create_tables2 with comment for test

test feature

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Oracle connection

Add Oracle database support for migration.
1st task to add connection to oracle database

Check id column

need to check the type id column before creating a dest id column with the uuid type

Docker Support

for docker environments, we will add a docker image to the hub in order run the tool in the container.

Create Conversion Class

Is your feature request related to a problem? Please describe.
New Feature

Describe the solution you'd like
One class that will convert data types

PyTest

Testing each function, class with pytest using fixtures

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.