{"id":21017316,"url":"https://github.com/richecr/duck-orm-cli","last_synced_at":"2025-03-13T17:17:13.383Z","repository":{"id":164963318,"uuid":"637581730","full_name":"richecr/duck-orm-cli","owner":"richecr","description":"DuckORM CLI is a database migration tool for usage with the DuckORM: https://github.com/richecr/duck-orm","archived":false,"fork":false,"pushed_at":"2023-05-14T00:17:23.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-20T12:24:25.022Z","etag":null,"topics":["app","cli","duckorm","library","orm","python3","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/richecr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-08T01:11:41.000Z","updated_at":"2023-06-02T00:16:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"eb97dd1e-cb28-4137-8669-cc27bcb50c48","html_url":"https://github.com/richecr/duck-orm-cli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richecr%2Fduck-orm-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richecr%2Fduck-orm-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richecr%2Fduck-orm-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richecr%2Fduck-orm-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richecr","download_url":"https://codeload.github.com/richecr/duck-orm-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243447635,"owners_count":20292452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["app","cli","duckorm","library","orm","python3","sql"],"created_at":"2024-11-19T10:18:51.783Z","updated_at":"2025-03-13T17:17:13.378Z","avatar_url":"https://github.com/richecr.png","language":"Python","readme":"# [DuckORM CLI](https://pypi.org/project/duck-orm-cli/)\n\nDuckORM CLI is a database migration tool for usage with the [DuckORM](https://github.com/richecr/duck-orm).\n\n**Requirements**: Python 3.10+\n\n**Duck-ORM-CLI is still in the early stages of development, production use is not recommended**.\n\n## Technology and Resources\n\n- [Python 3.10](https://www.python.org/downloads/release/python-3107/)\n- [Poetry](https://python-poetry.org/)\n- [Typer](https://typer.tiangolo.com/)\n- [Docker](https://www.docker.com/)\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Quickstart](#quickstart)\n- [Quickstart](#quickstart)\n    - [Commands](#commands)\n        - [init](#init)\n        - [create-migrate](#create-migrate)\n        - [create-seed](#create-seed)\n        - [run-migrations](#run-migrations)\n        - [undo-migrations-all](#undo-migrations-all)\n        - [create-seed](#create-seed)\n- [Author](#author)\n- [License](#license)\n\n## Installation\n\n```bash\n$ pip install duck-orm-cli\n```\n\n!!! note\n    Don't forget to install `databases` before installing `duck-orm-cli`. \n\n## Quickstart\n\nFor this example we will create a connection to the SQLite database and create a model.\n\n```bash\n$ pip install databases[sqlite]\n$ pip install ipython\n```\n\nNote that we want to use `ipython` here, because it supports using await expressions directly from the console.\n\n### Commands\n\n#### init\n\nThe command to create the initial settings for migrations.\n\n- Example\n\n```sh\nduck-orm-cli init\n```\n\nThis command will create the `duckorm_file.py` file with the structure below:\n\n```python\nconfigs = {\n    \"development\": {\n        \"client\": \"postgresql\", # dialect (or sqlite)\n        \"database_url\": \"url\", # uri (dev-duckorm:postgres123@localhost:5432/dev-duckorm)\n    },\n    \"production\": {\n        \"client\": \"postgresql\", # dialect (or sqlite)\n        \"database_url\": \"url\", # uri: dev-duckorm:postgres123@localhost:5432/dev-duckorm\n    },\n}\n```\n\nHere is where you must correctly configure the connection to your database.\n\n`OBS`: This command also creates the `migrations` and `seeds` folders.\n\n\n#### create-migrate \u003cname\u003e\n\nThe command to create a database migration.\n\n- Example\n\n```sh\nduck-orm-cli create-migrate create_users\n```\n\nThe file with `\u003ctimestamp\u003e_create_users.py` will be created with the structure:\n\n```python\nfrom duck_orm.sql import fields as Field\nfrom duck_orm.model_manager import ModelManager\n\n\nasync def up(model_manager: ModelManager):\n    await model_manager.create_table('users', {\n        'id': Field.Integer(primary_key=True, auto_increment=True),\n        'name': Field.String(),\n        'email': Field.String(unique=True)\n    })\n\n\nasync def down(model_manager: ModelManager):\n    await model_manager.drop_table('users')\n```\n\nWith the `up` and `down` methods. Where it is possible to describe what that migration will do and how the migration will be undone.\n\n\n#### create-seed \u003cname\u003e\n\nThe command to create a seed in your database.\n\n- Example\n\n```sh\nduck-orm-cli create-seed insert_user_admin\n```\n\nThe file with `\u003ctimestamp\u003e_insert_user_admin.py` will be created with the structure:\n\n```python\nfrom duck_orm.model_manager import ModelManager\nfrom duck_orm.sql.condition import Condition\n\n\ndef up(model_manager: ModelManager):\n    return model_manager.insert(\n        \"users\", [{\"id\": 1, \"name\": \"User 1\", \"email\": \"user1@gmail.com\"}]\n    )\n\n\ndef down(model_manager: ModelManager):\n    return model_manager.remove(\"users\", conditions=[Condition(\"id\", \"=\", 1)])\n```\n\nWith the `up` and `down` methods. Where it is possible to describe what that seed will do and how the seed will be undone.\n\n\n#### run-migrations\n\nThe command to perform all migrations on the database.\n\n- Example\n\n```sh\nduck-orm-cli run-migrations\n```\n\nThis command will take each created migration and run the `up` method and apply it to your database.\n\n#### undo-migrations-all\n\nThe command to undo all applied migrations on the database.\n\n- Example\n\n```sh\nduck-orm-cli undo-migrations-all\n```\n\nThis command will take each performed migration and run the `down` method and undo the change in your database.\n\n\n## Author\n\n- Rich Ramalho - [@richecr](https://github.com/richecr) - [@richzinho_ecr](https://twitter.com/richzinho_ecr)\n\n## License\n\n`Duck ORM CLI` is built as an open-source tool and remains completely free (MIT license).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichecr%2Fduck-orm-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichecr%2Fduck-orm-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichecr%2Fduck-orm-cli/lists"}