sysy-inc / zprp-23z-python-orm

Python ORM with web UI for CRUD operations,.
3 stars 0 forks source link

zprp-23z-python-orm

Migration engine

Installation

pip install skibidi-orm

Usage

Implementation of schema.py

Primary functionallity of the migration engine is to allow for easy megrations between different versions of the database, so structure of schema file should be defined by proprioetary library using migration engine.

Hovewer we can define example schema file as follows for example purposes:

# schema.py
# ...

class Table(MigrationElement):

    def __init__(self) -> None:
        self.adapter = SQLite3Adapter()

        models = Table.__subclasses__()
        if self.__class__ == Table:
            for cls in models:
                self.adapter.create_table(cls.__dict__["table"])

class Post(Table):
    columns = [
        SQLite3Typing.Column(
            name="post_id",
            data_type="INTEGER",
            column_constraints=[c.PrimaryKeyConstraint("Post", "post_id")],
        ),
        SQLite3Typing.Column(
            name="post_name",
            data_type="TEXT",
            column_constraints=[c.NotNullConstraint("Post", "post_name")],
        ),
    ]

    table = SQLite3Typing.Table(name="Post", columns=columns)

SQLite3Config("test_database.db")

Above we defined simple implementation of Table class which works as a base model for all SQL tables in our databse.

Normally Table class would be abstracted away by proprietary library, but for the sake of example we defined it here.

When he have defined our schema all interactions of end-user with the migration engine are done through CLI.

skibidi-orm

CLI tool for managing schema creations and migrations in Skibidi ORM.

Usage:

$ skibidi-orm [OPTIONS] COMMAND [ARGS]...

Options:

Commands:

skibidi-orm go

Go back (and forward) to specific migration.

Usage:

$ skibidi-orm go [OPTIONS] MIGRATION_ID

Arguments:

Options:

skibidi-orm log

List all migration revisions with their descriptions and ID.

Usage:

$ skibidi-orm log [OPTIONS]

Options:

skibidi-orm migrate

Used to run migration for current schema file. Can accept an optional message as a description of the migration.

Usage:

$ skibidi-orm migrate [OPTIONS]

Options:

skibidi-orm preview-migration

Preview the migration that will be executed.

Usage:

$ skibidi-orm preview-migration [OPTIONS]

Options:

skibidi-orm studio

Run web UI for CRUD operations on current DB.

Usage:

$ skibidi-orm studio [OPTIONS]

Options: