{"id":18044659,"url":"https://github.com/groonga/groonga-schema","last_synced_at":"2025-04-05T03:26:49.738Z","repository":{"id":56875359,"uuid":"64730304","full_name":"groonga/groonga-schema","owner":"groonga","description":"Ruby library and tool that processes Groonga schema","archived":false,"fork":false,"pushed_at":"2016-08-16T07:04:09.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-14T04:21:46.914Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/groonga.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":"2016-08-02T06:26:56.000Z","updated_at":"2016-08-05T02:49:50.000Z","dependencies_parsed_at":"2022-08-20T22:00:39.765Z","dependency_job_id":null,"html_url":"https://github.com/groonga/groonga-schema","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groonga%2Fgroonga-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groonga%2Fgroonga-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groonga%2Fgroonga-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groonga%2Fgroonga-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/groonga","download_url":"https://codeload.github.com/groonga/groonga-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284816,"owners_count":20913687,"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-10-30T18:10:11.506Z","updated_at":"2025-04-05T03:26:49.716Z","avatar_url":"https://github.com/groonga.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# README\n\n[![Gem Version](https://badge.fury.io/rb/groonga-schema.svg)](http://badge.fury.io/rb/groonga-schema)\n[![Build Status](https://travis-ci.org/groonga/groonga-schema.svg?branch=master)](https://travis-ci.org/groonga/groonga-schema)\n\n## Name\n\ngroonga-schema\n\n## Description\n\nGroonga-schema is a Ruby library and tool to processes [Groonga](http://groonga.org/)'s schema.\n\n## Install\n\n    % gem install groonga-schema\n\n## Usage\n\n### As a tool\n\nHere are command lines provided by groonga-schema:\n\n  * `groonga-schema-diff`: It reports difference between 2 schema.\n\n#### `groonga-schema-diff`\n\n`groonga-schema-diff` reports difference between 2 schema:\n\n```text\n% groonga-schema-diff FROM_SCHEMA TO_SCHEMA\n```\n\nThe output of `groonga-schema-diff` is a Groonga command list. It\nmeans that you can apply difference by processing the output of\n`groonga-schema-diff` by Groonga. The relation of them are similar to\n`diff` and `patch`.\n\nThe following example shows about it.\n\nHere are sample schema:\n\n`current.grn`:\n\n```text\ntable_create Logs TABLE_NO_KEY\ncolumn_create Logs timestamp COLUMN_SCALAR ShortText\n```\n\n`new.grn`:\n\n```text\ntable_create Logs TABLE_NO_KEY\ncolumn_create Logs timestamp COLUMN_SCALAR Time\n```\n\nIn the `current.grn` schema, `Logs.timestamp` column's value type is\n`ShortText`. In the `new.grn` schema, it's `Time`.\n\nHere is the output of `groonga-schema-diff`:\n\n```text\n% groonga-schema-diff current.grn new.grn\ncolumn_create --flags \"COLUMN_SCALAR\" --name \"timestamp_new\" --table \"Logs\" --type \"Time\"\ncolumn_copy --from_name \"timestamp\" --from_table \"Logs\" --to_name \"timestamp_new\" --to_table \"Logs\"\ncolumn_rename --name \"timestamp\" --new_name \"timestamp_old\" --table \"Logs\"\ncolumn_rename --name \"timestamp_new\" --new_name \"timestamp\" --table \"Logs\"\n\ncolumn_remove --name \"timestamp_old\" --table \"Logs\"\n```\n\nThe output Groonga command list does the followings:\n\n  1. Create a new column `Logs.timestamp_new`. The value type of the new column is `Time` not `ShortText`.\n\n  2. Copy data to `Logs.timestamp_new` from `Logs.timestamp`.\n\n  3. Rename `Logs.timestamp` to `Logs.timestamp_old`.\n\n  4. Rename `Logs.timestamp_new` to `Logs.timestamp`.\n\n  5. Remove `Logs.timestamp_old`.\n\nIt means that the output Groonga command list supports data migration.\n\nHere is a sample database to show data migration:\n\n```text\n% groonga DB_PATH dump\ntable_create Logs TABLE_NO_KEY\ncolumn_create Logs timestamp COLUMN_SCALAR ShortText\n\nload --table Logs\n[\n[\"_id\",\"timestamp\"],\n[1,\"2016-08-16 00:00:01\"],\n[2,\"2016-08-16 00:00:02\"],\n[3,\"2016-08-16 00:00:03\"],\n[4,\"2016-08-16 00:00:04\"],\n[5,\"2016-08-16 00:00:05\"]\n]\n```\n\nYou can apply the change by the following command lines:\n\n```text\n% groonga-schema-diff current.grn new.grn \u003e diff.grn\n% groonga --file diff.grn DB_PATH\n```\n\nOr:\n\n```text\n% groonga-schema-diff current.grn new.grn | groonga DB_PATH\n```\n\nHere is the sample database after applying the changes:\n\n```text\n% groonga DB_PATH dump\ntable_create Logs TABLE_NO_KEY\ncolumn_create Logs timestamp COLUMN_SCALAR Time\n\nload --table Logs\n[\n[\"_id\",\"timestamp\"],\n[1,1471273201.0],\n[2,1471273202.0],\n[3,1471273203.0],\n[4,1471273204.0],\n[5,1471273205.0]\n]\n```\n\n`Logs.timestamp` column's value type is changed to `Time` from\n`ShortText` and data are also converted.\n\nYou can also use `groonga-schema-diff` to remote databases.\n\nThe following command line shows difference between databases served\nat `http://192.168.0.1:10041` and `http://192.168.0.2:10041/`:\n\n```text\n% groonga-schema-diff \\\n    'http://192.168.0.1:10041/d/dump?dump_records=no' \\\n    'http://192.168.0.2:10041/d/dump?dump_records=no'\n```\n\nYou can apply the output Groonga command list by `groonga-client`\ncommand provided by `groonga-client-cli` gem:\n\n```text\n% groonga-client --host 192.168.0.1 diff.grn\n```\n\nThe following command synchronizes schema at\n`http://192.168.0.1:10041/` with schema at `http://192.168.0.1:10042/`:\n\n```text\n% groonga-schema-diff \\\n    'http://192.168.0.1:10041/d/dump?dump_records=no' \\\n    'http://192.168.0.2:10041/d/dump?dump_records=no' |\n  groonga-client --host 192.168.0.1\n```\n\nAfter this command line, the following command line outputs nothing\nbecause there are no difference between schema at\n`http://192.168.0.1:10041/` and `http://192.168.0.1:10042/`:\n\n```text\n% groonga-schema-diff \\\n    'http://192.168.0.1:10041/d/dump?dump_records=no' \\\n    'http://192.168.0.2:10041/d/dump?dump_records=no'\n%\n```\n\nNOTE: You should use database carefully while applying\nchanges. Because some tables and columns may be removed while applying\nchanges. If you touch removed tables and/or columns from another\nthreads, Groonga may be crashed. It's better that you reduce the max\nnumber of threads to 1 while applying changes like the following:\n\n```text\n% echo thread_limit 1 | groonga-client --host 192.168.0.1\n% groonga-schema-diff \\\n    'http://192.168.0.1:10041/d/dump?dump_records=no' \\\n    'http://192.168.0.2:10041/d/dump?dump_records=no' |\n  groonga-client --host 192.168.0.1\n% echo thread_limit 8 | groonga-client --host 192.168.0.1\n```\n\nNOTE: You can't use the `thread_limit` technique with `groonga-httpd`\nbecause `groonga-httpd` is multi-process model not multi-threading\nmodel. You need to reduce the number of workers by changing\n`worker_processes` to `1` in `groonga-httpd.conf` and reload the\nconfiguration file. You also need to increase the number of workers\nafter you apply the changes.\n\n### As a library\n\nTODO...\n\n## Dependencies\n\n* Ruby\n\n## Mailing list\n\n* English: [groonga-talk@lists.sourceforge.net](https://lists.sourceforge.net/lists/listinfo/groonga-talk)\n* Japanese: [groonga-dev@lists.sourceforge.jp](http://lists.sourceforge.jp/mailman/listinfo/groonga-dev)\n\n## Chat\n\n* English: [Gitter:groonga/en](https://gitter.im/groonga/en)\n* Japanese: [Gitter:groonga/ja](https://gitter.im/groonga/ja)\n\n## Authors\n\n* Kouhei Sutou \\\u003ckou@clear-code.com\\\u003e\n\n## License\n\nLGPLv2.1 or later. See doc/text/lgpl-2.1.txt for details.\n\n(Kouhei Sutou has a right to change the license including contributed patches.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgroonga%2Fgroonga-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgroonga%2Fgroonga-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgroonga%2Fgroonga-schema/lists"}