Mad migration
Project description
Database Migration Tool
Don't use this tool in production databases!! At this time tool under development!!
🧐 About
The Database Migration Tool was designed for those looking to migrate their data from one database to another. Basically, the tool is focused on transferring data from different database structures. Currently, the MySQL, Mariadb and Postgres driver related tool allows us to add NoSQL to SQL databases and vice versa. Our main goal is to make data migration possible in all environments.
Documentation: Documentation
🏁 Getting Started
Installing
pip install madmigration
🎈 Usage
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:
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://root:admin@127.0.0.1/oldDB"
- DestinationConfig:
dbURI: "mysql://root:admin@127.0.0.1/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
SourceConfigset the source database database configurationsdbURIsource database URI
DestinationConfigset the destination database configurationsdbURIdestination database URI
Configs:
- SourceConfig:
dbURI: "postgres://root:admin@127.0.0.1/oldDB" # set source database uri
- DestinationConfig:
dbURI: "mysql://root:admin@127.0.0.1/newDB" # set destination database uri
migrationTables section
migrationTablesin this configuration, you will write the source of the table that you have to migrate and the destination tables that will migrate the data.migrationTablespecify the source and destination table nameSourceTableinformation about source tablenamesource table name
DestinationTableinformation about destination tablenamedestination table namecreatebool 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
MigrationColumnsspecify source and destination columnsourceColumninformation about source columnnamesource column name
destinationColumninformation about destination columnnamedestination column nameoptionscolumn optionstype_castdestination 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://root:admin@127.0.0.1/old"
- DestinationConfig:
dbURI: "postgresql://root:admin@127.0.0.1/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
}
}
}
]
}
We will create all tables and database on the destination server if they do not exist
madmigrate -f migration_schema.yaml
✍️ Authors
See also the list of contributors who participated in this project.
Contributing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file madmigration-0.1.7.tar.gz.
File metadata
- Download URL: madmigration-0.1.7.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9a5c2ac7e738cf7526748408ccbc044eaa8cb1d5c216dad547cfc75550293c1
|
|
| MD5 |
62e4735bac68a26cfa5df8290efce501
|
|
| BLAKE2b-256 |
9197bb367a035b66a6253d57d5acb6e5de20bf90d3b8cfcb72fe9d0dc4c47ea4
|
File details
Details for the file madmigration-0.1.7-py3-none-any.whl.
File metadata
- Download URL: madmigration-0.1.7-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4976f82d8531b68a801e23841e4ac6adbca4b7263a8899dfdd3e029c8480d8eb
|
|
| MD5 |
61acbc519571b556115b28f1d2783a37
|
|
| BLAKE2b-256 |
ed74775b3ac6a90882d775fc83a75bf54e90ca12c46cac2fbb39104d5b6e6c44
|