Skip to main content

A powerful tool for managing multiple database environments in Flask applications

Project description

Flask-SQLAlchemy-Database-Orchestration

Türkçe | English

English

Flask-SQLAlchemy-Database-Orchestration is a powerful tool developed for managing multiple database environments in Flask applications. This tool accelerates development processes by facilitating database creation, initialization, and migration operations.

Features

  • SQLite database support
  • Automatic database creation
  • Migration management for single or all databases
  • Easy configuration
  • User-friendly interface with colored terminal outputs

Installation

  1. Install the package globally:
# Windows
pip install Flask-SQLAlchemy-Database-Orchestration

# Linux/Mac
pip3 install Flask-SQLAlchemy-Database-Orchestration
  1. Find the installation directory:
# Windows
pip show Flask-SQLAlchemy-Database-Orchestration

# Linux/Mac
pip3 show Flask-SQLAlchemy-Database-Orchestration

The Location parameter in the output shows the directory where the package is installed. Copy this directory.

Location: c:\users\x\appdata\roaming\python\python39\site-packages

  1. Create your own database orchestration application by copying the Flask-SQLAlchemy-Database-Orchestration package.
# Windows
Copy-Item -Path "Location\Flask_SQLAlchemy_Database_Orchestration" -Destination ".\ProjectName" -Recurse

Example:

Copy-Item -Path "c:\users\x\appdata\roaming\python\python39\site-packages\Flask_SQLAlchemy_Database_Orchestration" -Destination ".\ProjectName" -Recurse

# Linux/Mac
cp -r Location/Flask_SQLAlchemy_Database_Orchestration ./ProjectName

Example:

cp -r /usr/local/lib/python3.9/site-packages/Flask_SQLAlchemy_Database_Orchestration ./ProjectName
  1. Create a virtual environment:
# Windows
python -m venv .venv

# Linux/Mac
python3 -m venv .venv
  1. Activate the virtual environment:
# Windows
.venv\Scripts\activate

# Linux/Mac
source .venv/bin/activate
  1. Install Dependencies:
# Windows
pip install -r Requirements.txt

# Linux/Mac
pip3 install -r Requirements.txt

Usage

Database Type Configuration

You can specify the database type in the Utils/GeneralConfig.json file:

{
  "DB_TYPE": "SQLite"
}

Supported database types: SQLite

Database Configuration

Each database type has its own configuration file. For example, for SQLite: Utils/SQLiteConfig.json:

You can add as many databases as you want.

{
  "DATABASES": {
    "local": {
      "DATABASE_NAME": "FlaskLocal.db"
    },
    "dev": {
      "DATABASE_NAME": "FlaskDev.db"
    },
    "test": {
      "DATABASE_NAME": "FlaskTest.db"
    }
  }
}

1. Database Creation

To create databases:

python DbCreate.py

# Linux/Mac
python3 DbCreate.py

This command creates all databases defined in the relevant json file, such as Utils/SQLiteConfig.json, in the Assets/Databases folder according to the database type entered with DB_TYPE.

2. Database Initialization

To initialize database migration folders:

python DbInit.py

# Linux/Mac
python3 DbInit.py

When this command is run:

  1. Offers the option to initialize migration for a single database or all databases
  2. Creates Migrations/Migrations_{db_type}_{db_name} folders for selected databases
  3. Initializes database migration files with Flask-Migrate

3. Database Migration

To apply model changes to the database:

python DbMigrade.py

# Linux/Mac
python3 DbMigrade.py

When this command is run:

  1. Offers the option to migrate for a single database or all databases
  2. Performs migration for selected databases
  3. Reflects model changes to the database

Model Definition

Models are defined in the Models/Entity folder. An example model:

from Models.BaseModel.BaseModel import *
from Logix.DbManager.DbManager import db

class TestUsers(BaseModel, db.Model):
    __tablename__ = "TestUsers"

    Id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    UserId = db.Column(db.String(300), unique=True)
    Email = db.Column(db.String(100), unique=True)
    Name = db.Column(db.String(30))
    # ...

    def __init__(self, UserId, Email, Name, ...):
        self.UserId = UserId
        self.Email = Email
        self.Name = Name
        # ...

    def to_dict(self):
        return {prop: getattr(self, prop) for prop in dir(self) 
                if not prop.startswith('_') and not callable(getattr(self, prop))}

After creating a new model, don't forget to import it in the Models/Entity/_EntityExport.py file:

from Models.Entity.TestUsers import TestUsers
from Models.Entity.TestAuthentications import TestAuthentications
# ...

Project Structure

Flask-SQLAlchemy-Database-Orchestration/
├── Assets/
│   └── Databases/        # Database files
├── Logix/
│   ├── DbManager/        # Database management tools
│   └── Midware/          # Migration and helper tools
├── Migrations/           # Migration folders
├── Models/
│   ├── BaseModel/        # Base model classes
│   └── Entity/           # Database models
├── Utils/                # Configuration files
├── DbCreate.py           # Database creation
├── DbInit.py             # Migration initialization
├── DbMigrade.py          # Migration application
└── Requirements.txt      # Dependencies

License

This project is licensed under the MIT License.


Türkçe

Flask-SQLAlchemy-Database-Orchestration, Flask uygulamalarında çoklu veritabanı ortamlarını yönetmek için geliştirilmiş güçlü bir araçtır. Bu araç, veritabanı oluşturma, başlatma ve migrasyon işlemlerini kolaylaştırarak, geliştirme süreçlerini hızlandırır.

Özellikler

  • SQLite veritabanı desteği
  • Otomatik veritabanı oluşturma
  • Tek veya tüm veritabanları için migrasyon yönetimi
  • Kolay yapılandırma
  • Renkli terminal çıktıları ile kullanıcı dostu arayüz

Kurulum

  1. Paketi global olarak yükleyin:
# Windows
pip install Flask-SQLAlchemy-Database-Orchestration

# Linux/Mac
pip3 install Flask-SQLAlchemy-Database-Orchestration
  1. Paketin yüklendiği dizini bulun:
# Windows
pip show Flask-SQLAlchemy-Database-Orchestration

# Linux/Mac
pip3 show Flask-SQLAlchemy-Database-Orchestration

Çıktıda Location parametresi, paketin yüklendiği dizini gösterir. Bu dizini kopyalayın.

Location: c:\users\x\appdata\roaming\python\python39\site-packages

  1. Flask-SQLAlchemy-Database-Orchestration paketini kopyalayarak kendi database orchestration uygulamanızı oluşturun.
# Windows
Copy-Item -Path "Location\Flask_SQLAlchemy_Database_Orchestration" -Destination ".\ProjectName" -Recurse

Example:

Copy-Item -Path "c:\users\x\appdata\roaming\python\python39\site-packages\Flask_SQLAlchemy_Database_Orchestration" -Destination ".\ProjectName" -Recurse

# Linux/Mac
cp -r Location/Flask_SQLAlchemy_Database_Orchestration ./ProjectName

Example:

cp -r /usr/local/lib/python3.9/site-packages/Flask_SQLAlchemy_Database_Orchestration ./ProjectName
  1. VirtualEnvirüment oluşturun:
# Windows
python -m venv .venv

# Linux/Mac
python3 -m venv .venv
  1. VirtualEnvirüment'ü aktif edin:
# Windows
.venv\Scripts\activate

# Linux/Mac
source .venv/bin/activate
  1. Bağımlılıkları Yükleyin:
# Windows
pip install -r Requirements.txt

# Linux/Mac
pip3 install -r Requirements.txt

Kullanım

Veritabanı Tipi Yapılandırması

Veritabanı tipini Utils/GeneralConfig.json dosyasında belirleyebilirsiniz:

{
  "DB_TYPE": "SQLite"
}

Desteklenen veritabanı tipleri: SQLite

Veritabanı Yapılandırması

Her veritabanı tipi için kendi yapılandırma dosyası bulunmaktadır. Örneğin, SQLite için Utils/SQLiteConfig.json:

İstediğiniz kadar veri tabanı ekleyebilirsiniz.

{
  "DATABASES": {
    "local": {
      "DATABASE_NAME": "FlaskLocal.db"
    },
    "dev": {
      "DATABASE_NAME": "FlaskDev.db"
    },
    "test": {
      "DATABASE_NAME": "FlaskTest.db"
    }
  }
}

1. Veritabanı Oluşturma

Veritabanlarını oluşturmak için:

python DbCreate.py

# Linux/Mac
python3 DbCreate.py

Bu komut, DB_TYPE ile girilmiş olan veri tabanı tibine göre ilgili json dosyasındaki örneğin Utils/SQLiteConfig.json dosyasında tanımlanan tüm veritabanlarını Assets/Databases klasöründe oluşturur.

2. Veritabanı Başlatma (Init)

Veritabanı migrasyon klasörlerini başlatmak için:

python DbInit.py

# Linux/Mac
python3 DbInit.py

Bu komut çalıştırıldığında:

  1. Tek bir veritabanı veya tüm veritabanları için migrasyon başlatma seçeneği sunulur
  2. Seçilen veritabanları için Migrations/Migrations_{db_type}_{db_name} klasörleri oluşturulur
  3. Flask-Migrate ile veritabanı migrasyon dosyaları başlatılır

3. Veritabanı Migrasyon

Model değişikliklerini veritabanına uygulamak için:

python DbMigrade.py

# Linux/Mac
python3 DbMigrade.py

Bu komut çalıştırıldığında:

  1. Tek bir veritabanı veya tüm veritabanları için migrasyon seçeneği sunulur
  2. Seçilen veritabanları için migrasyon işlemi gerçekleştirilir
  3. Model değişiklikleri veritabanına yansıtılır

Model Tanımlama

Modeller Models/Entity klasöründe tanımlanır. Örnek bir model:

from Models.BaseModel.BaseModel import *
from Logix.DbManager.DbManager import db

class TestUsers(BaseModel, db.Model):
    __tablename__ = "TestUsers"

    Id = db.Column(db.Integer(), primary_key=True, autoincrement=True)
    UserId = db.Column(db.String(300), unique=True)
    Email = db.Column(db.String(100), unique=True)
    Name = db.Column(db.String(30))
    # ...

    def __init__(self, UserId, Email, Name, ...):
        self.UserId = UserId
        self.Email = Email
        self.Name = Name
        # ...

    def to_dict(self):
        return {prop: getattr(self, prop) for prop in dir(self) 
                if not prop.startswith('_') and not callable(getattr(self, prop))}

Yeni bir model oluşturduktan sonra, Models/Entity/_EntityExport.py dosyasına import etmeyi unutmayın:

from Models.Entity.TestUsers import TestUsers
from Models.Entity.TestAuthentications import TestAuthentications
# ...

Proje Yapısı

Flask-SQLAlchemy-Database-Orchestration/
├── Assets/
│   └── Databases/        # Veritabanı dosyaları
├── Logix/
│   ├── DbManager/        # Veritabanı yönetim araçları
│   └── Midware/          # Migrasyon ve yardımcı araçlar
├── Migrations/           # Migrasyon klasörleri
├── Models/
│   ├── BaseModel/        # Temel model sınıfları
│   └── Entity/           # Veritabanı modelleri
├── Utils/                # Yapılandırma dosyaları
├── DbCreate.py           # Veritabanı oluşturma
├── DbInit.py             # Migrasyon başlatma
├── DbMigrade.py          # Migrasyon uygulama
└── Requirements.txt      # Bağımlılıklar

Lisans

Bu proje MIT Lisansı altında lisanslanmıştır.

Project details


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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file Flask_SQLAlchemy_Database_Orchestration-1.0.3.tar.gz.

File metadata

File hashes

Hashes for Flask_SQLAlchemy_Database_Orchestration-1.0.3.tar.gz
Algorithm Hash digest
SHA256 7228a76c4885d6f7356b4b235f64a7f12e01a9091246305c6ce91c8a9276f5a1
MD5 15b29d9761f3f47fd89d578d0bacdf45
BLAKE2b-256 1b63fe17e9733d1448cab83ef3805e0cade83b5cd8ef65817361d25cc20b4f63

See more details on using hashes here.

File details

Details for the file Flask_SQLAlchemy_Database_Orchestration-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for Flask_SQLAlchemy_Database_Orchestration-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d3d6da05690f7998781a40c50a166d3607d355b1870fddf99dd8b518d4c6e3a6
MD5 3784d454e17b174abc042b8518efdb73
BLAKE2b-256 17c7b35df3d0a9a4b812ab390ae17eac1a77962012d3fe2f350fcde75d2fc0a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page