{"id":20590091,"url":"https://github.com/takehaya/peewee_seed","last_synced_at":"2025-04-14T22:26:15.464Z","repository":{"id":57451676,"uuid":"149393773","full_name":"takehaya/peewee_seed","owner":"takehaya","description":"peewee_seed is a seed library which provides initial data to database using peewee.","archived":false,"fork":false,"pushed_at":"2020-08-20T02:04:10.000Z","size":16,"stargazers_count":2,"open_issues_count":4,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T10:47:21.088Z","etag":null,"topics":["peewee","peewee-orm","seed","seed-database"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takehaya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-19T04:47:46.000Z","updated_at":"2022-05-29T23:39:47.000Z","dependencies_parsed_at":"2022-09-26T17:30:32.904Z","dependency_job_id":null,"html_url":"https://github.com/takehaya/peewee_seed","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/takehaya%2Fpeewee_seed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takehaya%2Fpeewee_seed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takehaya%2Fpeewee_seed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takehaya%2Fpeewee_seed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takehaya","download_url":"https://codeload.github.com/takehaya/peewee_seed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248970464,"owners_count":21191437,"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":["peewee","peewee-orm","seed","seed-database"],"created_at":"2024-11-16T07:33:59.108Z","updated_at":"2025-04-14T22:26:15.446Z","avatar_url":"https://github.com/takehaya.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# peewee_seed\npeewee_seed is a seed library which provides initial data to database using peewee.\nWith reference to the [Django fixture](https://docs.djangoproject.com/en/2.1/howto/initial-data/)\n\n[![CircleCI](https://circleci.com/gh/takehaya/peewee_seeds.svg?style=svg)](https://circleci.com/gh/takehaya/peewee_seeds)\n[![PyPI version](https://badge.fury.io/py/peewee-seed.svg)](https://badge.fury.io/py/peewee-seed)\n## usage\n\n### simple seeds\n- file envs\n```\n/myapp\n  __init__.py\n  seeds_entry.py\n  models.py\n  /fixtures\n    accounts.yaml\n```\n``` yaml\n# accounts.yaml\n- model : myapp.models.Account\n  id: 1\n  fields:\n    first_name: John\n    last_name: Smith\n    age: 20\n```\n```python\n# models.py\nfrom peewee import CharField\nfrom peewee import IntegerField\nfrom peewee import Model\nfrom peewee import SqliteDatabase\n\ndatabase = SqliteDatabase(\":memory:\", pragmas={\"foregin_keys\": 1})\n\n\nclass BaseModel(Model):\n    class Meta(object):\n        database = database\n\n\nclass Account(BaseModel):\n    first_name = CharField(null=False)\n    last_name = CharField(null=False)\n    age = IntegerField(null=True)\n```\n- seeds entry file\n``` python\n# seeds_entry.py\nfrom peewee_seeds import PeeweeSeed\nfrom myapp.models import database\n\n\ndef main():\n    path = '/path/to/fixtures'\n    \n    # seeds instance\n    seeds = PeeweeSeed(database, path, ['accounts.yaml'])\n    \n    # load fixture for create table\n    seeds.create_table_all()\n    \n    # load fixture for db input\n    seeds.db_data_input()\n\n\nif __name__ == '__main__':\n    main()\n```\n- Run command\n```\npython seeds_entroy.py\n```\n\n\n\n### other example\n\n```python\nfrom peewee_seed import PeeweeSeed\nfrom myapp.models import database\n\n# seeds instance\nseeds = PeeweeSeed()\n\n# set path\nseeds.set_path('/path/to/fixtures')\n\n# set use fixture name\nseeds.set_fixture_files(['accounts.yaml', 'pictures.yaml'])\n\n# loading fixture file data\nfixtures_row_data = seeds.load_fixture_files()\n\n# fixture  purification\nfields, models_namelist = seeds.load_fixture(fixtures_row_data[0])\n\n# fixtures purification\nfields, models_namelist = seeds.load_fixtures(fixtures_row_data)\n\n# set database session\nseeds.set_database(database)\n\n# base on fixtures, create tables\nseeds.create_table_all()\n\n# fixtures data to db input\nseeds.db_data_input(fixtures_row_data)\n\n# base on fixtures, drop tables \nseeds.drop_table_all()\n```\n\n### direct inputdata seed\n``` python\n# body is dict data\n# create \u0026 seed\nseed = PeeweeSeed(db)\n_, models = seed.load_fixtures([body])\nseed.create_table_all(models)\n\nseed.db_data_input([body])\n\n# body is modelpath(same to fixtures)\n# drop\nseed = PeeweeSeed(db)\n\nmodels = body[\"models\"]\nseed.drop_table_all(models)\n```\n\n#### error: Foreign key constraint\n\n```python\n\n# seed\nseed.db_data_input([body], foreign_key_checks=True)\n\n# db drop\nseed.drop_table_all(models, foreign_key_checks=True)\n\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakehaya%2Fpeewee_seed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakehaya%2Fpeewee_seed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakehaya%2Fpeewee_seed/lists"}