{"data":{"slug":"github-datopian-portaljs-skills-portaljs-define-schema-62c333e02dea","title":"PortalJS \u2014 Define Schema","summary":"Define a dataset's metadata profile by inferring a Frictionless Table Schema from its data, adding Data Package metadata (license, sources, keywords), and writing it into datasets.json so the showcase renders a typed field table. Requires a registered dataset and a scaffolded PortalJS portal with the metadata contract.","url":"https:\/\/skillshunter.net\/skills\/github-datopian-portaljs-skills-portaljs-define-schema-62c333e02dea","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-datopian-portaljs-skills-portaljs-define-schema-62c333e02dea","markdown_url":"https:\/\/skillshunter.net\/skills\/github-datopian-portaljs-skills-portaljs-define-schema-62c333e02dea.md","download_url":"https:\/\/skillshunter.net\/skills\/github-datopian-portaljs-skills-portaljs-define-schema-62c333e02dea\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Prerequisites include a scaffolded PortalJS portal with the metadata contract (`lib\/metadata\/types.ts`, `pages\/[owner]\/[slug].tsx`), a registered dataset in `datasets.json`, and the dataset's CSV\/TSV file present under `PORTAL_DIR\/public\/data\/`. Node 18+ is required.","instructions":"---\nname: portaljs-define-schema\ndescription: Define a dataset's metadata profile \u2014 infer a Frictionless Table Schema from its data, add Data Package metadata (license, sources, keywords), and write it into datasets.json so the showcase renders a typed field table. Extend or customize via the L0-L3 profile ladder. Use when a registered dataset needs field types, constraints, or catalog metadata before publishing.\nallowed-tools: Read, Write, Edit, Bash(npx:*), Bash(node:*), Bash(head:*)\nversion: 1.0.0\nauthor: Datopian <hello@datopian.com>\nlicense: MIT\ncompatibility: Claude Code with PortalJS portals (Next.js 14, React 18, Node 18+). Runs from any project via the plugin, a personal ~\/.claude\/commands install, or a portaljs clone.\ntags:\n  - portaljs\n  - data-portal\n  - schema\n  - frictionless\n  - metadata\n  - datapackage\n---\n\n# PortalJS \u2014 Define Schema\n\n## Overview\n\nDefine a dataset's metadata profile \u2014 the **authoring** skill for the metadata-profile\ncontract (`lib\/metadata`). Where `portaljs-add-dataset` registers *that* a dataset exists,\nthis skill describes *what its data means*: infer a Frictionless **Table Schema** (fields,\ntypes, constraints) from sampled data, add the **Data Package** fields a catalog surfaces\n(title, licenses, sources, keywords), and write them onto the dataset's entry in\n`datasets.json`. The showcase at `\/@<namespace>\/<slug>` then renders a typed field table\ninstead of a bare preview. The model is Frictionless-native; DCAT is a serialization layer\nbuilt on top later, not authored here.\n\nThe skill runs on a profile ladder \u2014 reach for higher levels only when needed:\n\n| Level | What it is | When |\n| --- | --- | --- |\n| L0 | Default `frictionless-tabular` profile; declare schema + metadata. | Default. Standard tabular CSV\/TSV. |\n| L1 | L0 plus extra descriptive package fields. | Extra metadata, standard validation is fine. |\n| L2 | Fully custom profile (own schema template + `validate()`). | A dataset type needing custom validation rules. |\n| L3 | Multiple registered profiles, resolved per dataset. | A portal mixing dataset types. |\n\nThe skill is interactive and never dead-ends: if input is thin it interviews in short\nrounds, infers defaults from the data, echoes the schema for confirmation, and accepts\n\"use defaults\" to proceed with the inferred schema as-is.\n\n## Prerequisites\n\n- A scaffolded PortalJS portal with the metadata contract (`lib\/metadata\/types.ts`,\n  `pages\/[owner]\/[slug].tsx`); see `portaljs-new-portal`.\n- The target dataset already registered in `datasets.json` (see `portaljs-add-dataset`).\n- For tabular schema inference, the dataset's CSV\/TSV file present under\n  `PORTAL_DIR\/public\/data\/`. JSON\/GeoJSON datasets get package metadata only \u2014 no `fields`.\n- Node 18+; `tsx` optional, used for the schema-validation check.\n\n## Instructions\n\nThe canonical, full step-by-step workflow is\n[`.claude\/commands\/portaljs-define-schema.md`](https:\/\/github.com\/datopian\/portaljs\/blob\/main\/.claude\/commands\/portaljs-define-schema.md) \u2014\nthe single source of truth. Read and follow it when executing. Summary:\n\n1. Gather `PORTAL_DIR`, `DATASET` (slug or `namespace\/slug`), and `LEVEL` (default `L0`)\n   from input; if `DATASET` is missing, list the portal's slugs and ask.\n2. Validate the portal has the metadata contract (`datasets.json`, `lib\/metadata\/types.ts`,\n   the showcase route); proceed anyway if `lib\/metadata\/` predates the contract.\n3. For tabular datasets, sample the header and ~50 rows from `public\/data\/<file>` and infer\n   each field's type, constraints (`required`, `unique`, `pattern`), and a primary key.\n4. Echo the inferred schema as a table for confirmation; offer to go beyond L0 only if\n   warranted.\n5. Ask for optional Data Package metadata: license, source(s), keywords, version.\n6. Write the schema and metadata onto the dataset's entry in `datasets.json` in place,\n   preserving all other fields; for L2\/L3, scaffold and register a custom profile module.\n7. Optionally validate the schema against the data's rows via the profile's `validate()`.\n8. Verify with `npx next build`; fix malformed JSON or an invalid `FieldType` before\n   reporting success.\n9. Report the profile, fields, metadata set, and the showcase URL.\n\n## Output\n\n- **Modified:** `datasets.json` (target entry gains `profile`, `schema`, `licenses`,\n  `sources`, `keywords`, `version` \u2014 unset fields omitted).\n- **Created (L2\/L3 only):** `lib\/metadata\/<profile-id>.ts`; `lib\/metadata\/registry.ts`\n  updated with a `registerProfile(...)` call.\n- **Verified:** `npx next build` succeeds.\n- **Result:** `\/@<namespace>\/<slug>` renders a typed field table in place of a bare preview.\n\n## Error Handling\n\n| Symptom | Cause | Fix |\n| --- | --- | --- |\n| Dataset not found in `datasets.json` | Wrong slug or missing `namespace\/` prefix | List available slugs and re-prompt. |\n| `lib\/metadata\/` missing | Portal predates the metadata-profile contract | Proceed anyway \u2014 schema fields are optional and ignored by older showcases. |\n| No `fields` schema produced | Dataset is JSON\/GeoJSON, not tabular | Expected \u2014 capture Data Package metadata only. |\n| Validation reports type errors | Sampled values don't coerce to the inferred type | Relax the `type` or drop the offending `required`\/`pattern` constraint. |\n| `next build` fails on `datasets.json` | Stray comma or a type outside `FieldType` | Fix the JSON\/type and rebuild before reporting success. |\n\n## Examples\n\n### Example 1 \u2014 Default L0 schema for a CSV dataset\n\n```\n\/portaljs-define-schema population-2022\n```\nInfers fields (e.g. `country: string`, `population: integer`), drafts titles, asks for a\nlicense and source, and writes the schema under the default `frictionless-tabular` profile.\n\n### Example 2 \u2014 Metadata only for a GeoJSON dataset\n\n```\n\/portaljs-define-schema neighborhoods-geo\n```\nGeoJSON has no tabular `fields`; the skill captures license, sources, and keywords onto the\nentry and skips schema inference.\n\n### Example 3 \u2014 Custom L2 profile with its own validation\n\n```\n\/portaljs-define-schema co2-emissions level=L2\n```\nScaffolds `lib\/metadata\/co2-emissions-profile.ts` with a custom `validate()`, registers it\nin `lib\/metadata\/registry.ts`, and sets `\"profile\": \"co2-emissions-profile\"` on the entry.\n\n## Resources\n\n- Full workflow: [`.claude\/commands\/portaljs-define-schema.md`](https:\/\/github.com\/datopian\/portaljs\/blob\/main\/.claude\/commands\/portaljs-define-schema.md)\n- Field-type and troubleshooting reference: [`references\/reference.md`](references\/reference.md)\n- Related skills: `portaljs-add-dataset`, `portaljs-add-dcat`, `portaljs-check-data-quality`\n- Frictionless Table Schema specification: <https:\/\/datapackage.org\/standard\/table-schema\/>\n","use_cases":["Define schema for a CSV dataset with inferred field types and constraints","Add Data Package metadata (license, sources, keywords) to a registered dataset","Customize schema validation rules for a dataset with unique requirements"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/datopian\/portaljs\/blob\/fc7ccd651459549a962c8b7aa08f60f8849fd9a5\/skills\/portaljs-define-schema\/SKILL.md","source_commit":"fc7ccd651459549a962c8b7aa08f60f8849fd9a5","license":"MIT","version":"1.0.0","listing_approved_at":"2026-11-22","created_at":"2026-11-21T15:55:03.000000Z","updated_at":"2026-11-22T11:18:24.000000Z","seo_title":"Define Dataset Schema with PortalJS","seo_description":"Define a dataset's metadata profile using PortalJS. Infer schema, add metadata, and write to datasets.json for typed field table rendering.","seo_keywords":["define dataset schema","portaljs schema inference","data package metadata","frictionless table schema","dataset metadata profile"]}}