Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/denismurphy/schema-duplicator

Schema Duplicator
https://github.com/denismurphy/schema-duplicator

duplicate mysql procedure schema sql tables

Last synced: 2 months ago
JSON representation

Schema Duplicator

Awesome Lists containing this project

README

        

# 🔄 Schema Duplicator

This SQL script duplicates a schema without referential integrity. It creates a copy of the schema by iterating over all tables in the source schema, creating and inserting them into the target schema. The copy process does not include foreign key constraints.

## 📋 Prerequisites

- 🐬 MySQL
- 🔑 Administrative privileges

## 🚀 Usage

To use this script, simply call the `duplicate_schema` stored procedure and pass in the source and target schema names as parameters. For example:

```sql
CALL duplicate_schema('source_schema', 'target_schema');
```

## 📝 Procedure Steps

1. 📍 Declare cursor and handler
2. 🏗️ Create target schema if it doesn't exist
3. 📜 Get a list of tables in the source schema
4. 🔁 Loop through the tables and create and insert into corresponding tables in the target schema
5. 🗑️ Drop any foreign key constraints on the new table
6. 📤 Output to SQL
7. 🚪 Close the cursor

## ⚠️ Limitations

This script does not copy foreign key constraints between tables. Therefore, the target schema will not have the same referential integrity as the source schema.

## 📄 License

This script is licensed under the MIT License.