|
1 |
| -# devtool-db |
| 1 | +# DB Migration Tool |
| 2 | + |
| 3 | +`Open-Source` project that provides simple helpers for database migrations. |
| 4 | + |
| 5 | +<br /> |
| 6 | + |
| 7 | +> Features |
| 8 | +
|
| 9 | +- `Peewee` DB Reflection |
| 10 | +- Supported DB: |
| 11 | + - SQLite, MySql, PostgreSQL |
| 12 | +- DbWrapper Class: |
| 13 | + - `print_all_models()` - returns all tables |
| 14 | + - `print_db_model` - print table definition |
| 15 | + - `dump_tables()` - Dump SQL definitions (all tables) |
| 16 | + - `dump_tables_data()` - Dump database content (all tables) |
| 17 | +- [Support](https://appseed.us/support) via **Github** (issues tracker) and [Discord](https://discord.gg/fZC6hup). |
| 18 | + |
| 19 | +<br /> |
| 20 | + |
| 21 | +## ✨ Quick Start |
| 22 | + |
| 23 | +> Clone Sources (this repo) |
| 24 | +
|
| 25 | +```bash |
| 26 | +$ git clone https://github.com/app-generator/devtool-db.git |
| 27 | +$ cd devtool-db |
| 28 | +``` |
| 29 | + |
| 30 | +<br /> |
| 31 | + |
| 32 | +> Install Modules using a Virtual Environment |
| 33 | +
|
| 34 | +```bash |
| 35 | +$ virtualenv env |
| 36 | +$ source env/bin/activate |
| 37 | +$ pip install -r requirements.txt |
| 38 | +``` |
| 39 | + |
| 40 | +Or for **Windows-based Systems** |
| 41 | + |
| 42 | +```bash |
| 43 | +$ virtualenv env |
| 44 | +$ .\env\Scripts\activate |
| 45 | +$ |
| 46 | +$ # Install modules - SQLite Database |
| 47 | +$ pip3 install -r requirements.txt |
| 48 | +``` |
| 49 | + |
| 50 | +<br /> |
| 51 | + |
| 52 | +> Launch the Python console |
| 53 | +
|
| 54 | +```bash |
| 55 | +$ python |
| 56 | +>>> |
| 57 | +>>> from util import * # import helpers |
| 58 | +>>> |
| 59 | +>>> db_sqlite = DbWrapper() # invoke the Base Class |
| 60 | +>>> db_sqlite.driver = COMMON.DB_SQLITE # set driver |
| 61 | +>>> db_sqlite.db_name = 'samples/api-django.sqlite3' # set db name |
| 62 | +>>> db_sqlite.connect() # connect |
| 63 | +True |
| 64 | +>>> db_sqlite.load_models() # load DB SChema |
| 65 | +True |
| 66 | +>>> db_sqlite.dump_tables() # Dump tables definitions |
| 67 | +True |
| 68 | +>>> db_sqlite.dump_tables_data() # Dump data |
| 69 | + > Dump data for [api_user_user] |
| 70 | + > Dump data for [api_authentication_activesession] |
| 71 | + > Dump data for [auth_group] |
| 72 | + > Dump data for [api_user_user_groups] |
| 73 | + > Dump data for [django_content_type] |
| 74 | + > Dump data for [auth_permission] |
| 75 | + > Dump data for [api_user_user_user_permissions] |
| 76 | + > Dump data for [auth_group_permissions] |
| 77 | + > Dump data for [django_admin_log] |
| 78 | + > Dump data for [django_migrations] |
| 79 | + > Dump data for [django_session] |
| 80 | +True |
| 81 | +>>> db_sqlite.reset() # reset the Class data |
| 82 | +>>> |
| 83 | +``` |
| 84 | + |
| 85 | +<br /> |
| 86 | + |
| 87 | +At this point, the tables and data are saved in the `output` directory. |
| 88 | + |
| 89 | +```bash |
| 90 | +$ cd output ; ls |
| 91 | +$ SQLITE.sql |
| 92 | +$ SQLITE_api_user_user.sql |
| 93 | +$ SQLITE_auth_permission.sql |
| 94 | +$ SQLITE_django_content_type.sql |
| 95 | +$ SQLITE_django_migrations.sql |
| 96 | +``` |
| 97 | + |
| 98 | +<br /> |
| 99 | + |
| 100 | +--- |
| 101 | +DB Migration Tool - Provided by **AppSeed** [App Generator](https://appseed.us/app-generator). |
0 commit comments