{"id":22092104,"url":"https://github.com/krakphp/static-seed","last_synced_at":"2025-03-23T23:44:53.457Z","repository":{"id":57009053,"uuid":"100136970","full_name":"krakphp/static-seed","owner":"krakphp","description":"Static Seeding for managing lookup tables","archived":false,"fork":false,"pushed_at":"2019-09-20T04:17:03.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T06:52:19.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/krakphp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-12T20:45:56.000Z","updated_at":"2019-09-20T04:12:38.000Z","dependencies_parsed_at":"2022-08-21T14:50:51.287Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/static-seed","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fstatic-seed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fstatic-seed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fstatic-seed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fstatic-seed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/static-seed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186923,"owners_count":20574554,"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":[],"created_at":"2024-12-01T03:08:20.105Z","updated_at":"2025-03-23T23:44:53.432Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Static Seed\n\nStatic Seed provides a way to manage lookup table data in a reliable and maintainable away. Obviating the need for complex migration files or custom synchronization scripts, static seed allows you to define your table information in JSON and import/export into and from your database.\n\n## Installation\n\nInstall with composer at `krak/static-seed`\n\n## Usage\n\n```php\n\u003c?php\n\nuse Krak\\StaticSeed;\n\nconst SEED_DIR = __DIR__ . '/path/to/seed/dir';\n\n/** Setup the export tables */\nfunction export(StaticSeed\\Export $export) {\n    $export-\u003eexport([\n        new StaticSeed\\Table('colors', 'tuple'),\n        new StaticSeed\\Table('color_sets', 'struct'),\n        StaticSeed\\Table::createJoin('color_sets_colors', 'color_set_id', [\n            'color_set_id' =\u003e ['table' =\u003e 'color_sets', 'field' =\u003e 'slug'],\n            'color_id' =\u003e ['table' =\u003e 'colors', 'field' =\u003e 'slug'],\n        ])\n    ], SEED_DIR);\n}\n\nfunction import(StaticSeed\\Import $import) {\n    $import-\u003eimport(SEED_DIR);\n}\n\nfunction usage($argv) {\n    printf(\"usage: %s \u003cexport|import\u003e\\n\", $argv[0]);\n    return 1;\n}\n\nfunction main($argv) {\n    if (count($argv) \u003c= 1) {\n        exit(usage($argv));\n    }\n\n    $conn = myDoctrineDbalConnection();\n\n    if ($argv[1] == 'export') {\n        export(new StaticSeed\\Export($conn));\n    } else if ($argv[1] == 'import') {\n        import(new StaticSeed\\Import($conn));\n    } else {\n        exit(usage($argv));\n    }\n}\n\nmain($argv);\n```\n\nExporting will generate a set of files that look like this:\n\n- colors.json\n- colors_sets.json\n- colors_sets_colors.json\n\ncolors.json:\n\n```json\n{\n    \"name\": \"colors\",\n    \"row_type\": \"tuple\",\n    \"type\": \"normal\",\n    \"fields\": [\"id\", \"name\", \"slug\", \"hex\", \"sort\", \"type\"],\n    \"rows\": [\n        [1, \"Red\", \"red\", \"#ff0000\", 0, \"normal\"],\n        [2, \"Green\", \"green\", \"#00ff00\", 0, \"normal\"],\n        [3, \"Blue\", \"blue\", \"#0000ff\", 0, \"normal\"],\n    ]\n}\n\n```\n\ncolor_sets.json:\n\n```json\n{\n    \"name\": \"color_sets\",\n    \"row_type\": \"struct\",\n    \"type\": \"normal\",\n    \"fields\": [\"id\", \"name\", \"slug\"],\n    \"rows\": [\n        {\"id\": 1, \"name\": \"Color Set 1\", \"slug\": \"color-set-1\"},\n        {\"id\": 1, \"name\": \"Color Set 2\", \"slug\": \"color-set-2\"}\n    ]\n}\n```\n\ncolor_sets_colors.json:\n\n```json\n{\n    \"name\": \"color_sets_colors\",\n    \"type\": \"join\",\n    \"row_type\": \"tuple\",\n    \"index_by\": \"color_set_id\",\n    \"fields\": [\n        \"color_set_id\",\n        \"color_id\"\n    ],\n    \"map_id\": {\n        \"color_set_id\": {\n            \"table\": \"color_sets\",\n            \"field\": \"slug\"\n        },\n        \"color_id\": {\n            \"table\": \"colors\",\n            \"field\": \"slug\"\n        }\n    },\n    \"rows\": {\n        \"color-set-1\": [\n            \"red\",\n            \"green\",\n        ],\n        \"color-set-2\": [\n            \"green\",\n            \"blue\"\n        ]\n    }\n}\n```\n\n### Symfony Installation\n\nRegister the following in your config/bundles.php to install the symfony bundle.\n\n```php\n    Krak\\StaticSeed\\Bridge\\Symfony\\StaticSeedBundle::class =\u003e ['all' =\u003e true],\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fstatic-seed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Fstatic-seed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fstatic-seed/lists"}