{"id":15187598,"url":"https://github.com/thinkmill/keystone-mosql-yaml-gen","last_synced_at":"2026-03-02T18:34:40.582Z","repository":{"id":57166282,"uuid":"61362718","full_name":"Thinkmill/keystone-mosql-yaml-gen","owner":"Thinkmill","description":null,"archived":false,"fork":false,"pushed_at":"2018-05-02T22:24:04.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-25T18:47:59.311Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/Thinkmill.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-06-17T09:33:34.000Z","updated_at":"2018-05-02T22:23:58.000Z","dependencies_parsed_at":"2022-08-30T15:20:48.776Z","dependency_job_id":null,"html_url":"https://github.com/Thinkmill/keystone-mosql-yaml-gen","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fkeystone-mosql-yaml-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fkeystone-mosql-yaml-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fkeystone-mosql-yaml-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fkeystone-mosql-yaml-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thinkmill","download_url":"https://codeload.github.com/Thinkmill/keystone-mosql-yaml-gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240859953,"owners_count":19869248,"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-09-27T18:40:28.910Z","updated_at":"2026-03-02T18:34:40.516Z","avatar_url":"https://github.com/Thinkmill.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"MoSQL Yaml Generator for Keystone\n================================================================================\n\nTools for generating a [MoSQL](https://github.com/stripe/mosql)-compatible YAML document describing the lists configured for your [Keystone 4](http://keystonejs.com) instance.\nThis can be useful for exporting data from a Keystone instance or streaming updates to a reporting database in near real-time.\n\nYou'll need to install [MoSQL](https://github.com/stripe/mosql) and [PostgreSQL](https://www.postgresql.org/download) separately.\n\n\nUsage\n--------------------------------------------------------------------------------\n\n### Generating the Config\n\n```javascript\nconst keystone = require('keystone');\nconst mosqlYaml = require('@thinkmill/keystone-mosql-yaml-gen');\n\n// Create a generator instance\nconst yamlGenerator = new mosqlYaml.YamlGenerator(keystone);\n\n// Extract the MoSQL YAML for your lists\nconst collectionsYaml = yamlGenerator.generateYaml();\nconsole.log(collectionsYaml);\n```\n\n#### Express Endpoint\n\nA drop-in [ExpressJS](https://expressjs.com) endpoint is included.\nThis can be useful if your schema is often changing; a process could be configured to periodically download an up-to-date config.\n\nAdd the endpoint to your Express app like this:\n\n```javascript\nconst keystone = require('keystone');\nconst mosqlYaml = require('@thinkmill/keystone-mosql-yaml-gen');\n\napp.get('/api/keystoneListsYaml', mosqlYaml.createMosqlYamlEndpoint(keystone));\n```\n\nAlternatively, create your own endpoint:\n\n```javascript\nconst keystone = require('keystone');\nconst mosqlYaml = require('@thinkmill/keystone-mosql-yaml-gen');\n\nconst endpoint = function (req, res, next) {\n\tconst yamlGenerator = new mosqlYaml.YamlGenerator(keystone);\n\tconst collectionsYaml = yamlGenerator.generateYaml();\n\n\tres.set('content-disposition', `attachment; filename=\"${yamlGenerator.getFilename()}\"`);\n\tres.set('content-Type', 'application/x-yaml');\n\tres.send(collectionsYaml);\n};\n```\n\n### Consuming the Config\n\nThe config generated describes the collections and fields to copy.\nIt's supplied to `mosql` like this:\n\n```sh\nmosql -c 180502-keystone-MoSQL.yaml [--sql postgres://sql-server/sql-db] [--mongo mongodb://mongo-uri]\n```\n\nSee the [MoSQL](https://github.com/stripe/mosql) docs for more options.\n\n\nTypes\n--------------------------------------------------------------------------------\n\n### Strings\n\nUnlike other database systems, in PostgreSQL, there is no performance difference between `varchar`, `varchar(n)` and `text` types.\nWe preference `text`.\n\n### Numbers\n\nNumbers in JavaScript are 64-bit floating points; equivalent to PGs `double precision` type.\n\nNote that for `Money` fields are also imported as `double precision`.\nThese values should be converted to a lossless type before being manipulated (eg. `numeric(20, 4)` or similar).\n\n### Dates\n\nJavaScript `Date` objects have no timezone information -- they're epoch-base and effectively in UTC.\nImporting as `timestamp with time zone` will maintaining the correct value while defaulting the time zone stored to UTC.\n\n`Date` objects also maintain only millisecond precision (ie. 1/1,000 of a second).\nPostgreSQL on the other hand, defaults to microsecond precision for it's `timestamp` types (ie. 1/1,000,000 of a second).\nThis tool sticks with the Postgres default but column types could later be altered to `timestamp (3) with time zone` without any data loss.\n\n### Passwords\n\nCurrently passwords are intentionally excluded from the dumped fields.\n\n(TODO: Add configuration options for this)\n\n### Simple Type Mappings\n\nValues are mapped to individual columns where possible:\n\n| Keystone Type | PostgreSQL Type | Notes |\n|---------------|-----------------|-------|\n| `datetime` | `timestamp with time zone` | See [Dates](#dates) above |\n| `date` | `timestamp with time zone` |  |\n| `number` | `double precision` |  |\n| `relationship` | `text` | When `many !== true` |\n| `relationship` | `text array` | When `many === true` |\n| `select` | `text` |  |\n| `text` | `text` |  |\n| `boolean` | `boolean` |  |\n| `code` | `text` |  |\n| `email` | `text` |  |\n| `html` | `text` |  |\n| `markdown` | `text` |  |\n| `textarea` | `text` |  |\n| `money` | `double precision` | See [Numbers](#numbers) above |\n| `geopoint` | `double precision array` |  |\n| `textarray` | `text array` |  |\n\n### Complex Type Mappings\n\nSome of the more complex, multi-value types are mapped to multiple columns:\n\n#### `name` Type\n\n| Keystone Field | Column Name | PostgreSQL Type |\n|----------------|-------------|-----------------|\n| `(key).first` | `(key)_first` | `text` |\n| `(key).last` | `(key)_last` | `text` |\n\n#### `location` Type\n\n| Keystone Field | Column Name | PostgreSQL Type |\n|----------------|-------------|-----------------|\n| `(key).street1` | `(key)_street1` | `text` |\n| `(key).street2` | `(key)_street2` | `text` |\n| `(key).name` | `(key)_building_name` | `text` |\n| `(key).shop` | `(key)_shop` | `text` |\n| `(key).number` | `(key)_number` | `text` |\n| `(key).state` | `(key)_state` | `text` |\n| `(key).postcode` | `(key)_postcode` | `text` |\n| `(key).suburb` | `(key)_suburb` | `text` |\n| `(key).geo` | `(key)_geo` | `double precision array` |\n\n#### `s3file` Type\n\n| Keystone Field | Column Name | PostgreSQL Type |\n|----------------|-------------|-----------------|\n| `(key).filename` | `(key)_filename` | `text` |\n| `(key).originalname` | `(key)_originalname` | `text` |\n| `(key).path` | `(key)_path` | `text` |\n| `(key).size` | `(key)_size` | `int` |\n| `(key).filetype` | `(key)_filetype` | `text` |\n| `(key).url` | `(key)_url` | `text` |\n\n#### `cloudinaryimage` Type\n\n| Keystone Field | Column Name | PostgreSQL Type |\n|----------------|-------------|-----------------|\n| `(key).public_id` | `(key)_public_id` | `text` |\n| `(key).version` | `(key)_version` | `int` |\n| `(key).signature` | `(key)_signature` | `text` |\n| `(key).width` | `(key)_width` | `int` |\n| `(key).height` | `(key)_height` | `int` |\n| `(key).format` | `(key)_format` | `text` |\n| `(key).resource_type` | `(key)_resource_type` | `text` |\n| `(key).url` | `(key)_url` | `text` |\n| `(key).secure_url` | `(key)_secure_url` | `text` |\n\n\nNaming\n--------------------------------------------------------------------------------\n\nColumn names are forced to lowercase and restricted to the character set `[a-zA-Z0-9_]`.\nAny whitespace, hyphens or stops are replaced with underscores.\n\n(TODO: Add configuration options for this)\n\n\n--------------------------------------------------------------------------------\n\nDeveloped by [John Molomby](https://github.com/molomby) at [Thinkmill](http://www.thinkmill.com.au) for [Keystone.js](http://keystonejs.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkmill%2Fkeystone-mosql-yaml-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkmill%2Fkeystone-mosql-yaml-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkmill%2Fkeystone-mosql-yaml-gen/lists"}