[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EVN5DJ3ZWVT016X0266PZA":3,"skill-same:01M7EVN5DJ3ZWVT016X0266PZA":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7EVN5DJ3ZWVT016X0266PZA","lmfdb-object-to-database",null,"Insert or update an LMFDB wrapper object directly into the lmfdb PostgreSQL schema, bypassing the DATA\u002F flat-file step. Use whenever the user has a live LMFDBXxx object and wants to persist it to the database without writing a file first, or when asked to \"save this to the database\" after computing something.","tdupu\u002Fagent-skills-public","tdupu","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F3440403?v=4","01M7EV32X9J0EFE5T4P8TKQTCQ","Taylor Dupuy","01M7EV32XZ1Z4MDBYAFRCJD3BP",0,"GPL-3.0","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fskills\u002Flmfdb-object-to-database\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: lmfdb-object-to-database\ndescription: Insert or update an LMFDB wrapper object directly into the lmfdb PostgreSQL schema, bypassing the DATA\u002F flat-file step. Use whenever the user has a live LMFDBXxx object and wants to persist it to the database without writing a file first, or when asked to \"save this to the database\" after computing something.\n---\n\n# lmfdb-object-to-database\n\n## Dependency check\n\n```bash\n# Discover conf: project root first, hecke fallback\nCONF=\"\"\nfor candidate in \\\n    \"$(git rev-parse --show-toplevel 2>\u002Fdev\u002Fnull)\u002Flmfdb-pipeline.conf\" \\\n    \"magma\u002Fscripts\u002Fdata-generation.conf\"; do\n  [ -f \"$candidate\" ] && { CONF=\"$candidate\"; break; }\ndone\nif [ -z \"$CONF\" ]; then\n  echo \"I'm sorry, I can't do that — no database pipeline conf found.\"\n  echo \"Run \u002Fconfigure-database (mathcity-lmfdb.configure-database) to create lmfdb-pipeline.conf at your project root.\"\n  echo \"(This conf holds your PostgreSQL and DATA_DIR settings for the LMFDB pipeline.)\"\n  exit 1\nfi\nsource \"$CONF\"\n```\n\n```magma\nZ := Integers(); Q := Rationals();\nAttachSpec(\"hecke.spec\");\nSetLMFDBRootFolder(\".\");\n\ndb := OpenDB(\"clifford_bianchi_local\");\n\n\u002F\u002F Single object insert (errors if label already exists):\nAddLMFDB(db, \"LMFDBCliffOrd\", [X]);\n\n\u002F\u002F Upsert (overwrite existing row):\nAddLMFDB(db, \"LMFDBCliffOrd\", [X] : overwrite := true);\n\n\u002F\u002F Batch insert:\nAddLMFDB(db, \"LMFDBPSL2GrpCliffSub\", subs);\n\n\u002F\u002F Generic low-level insert (Assoc-level):\nAdd(db, \"clifford_orders\", [Dictionary(X)] : overwrite := true);\n```\n\n`AddLMFDB` checks that each object has a non-empty `label` attribute before inserting. With `overwrite := false` (default), the INSERT will error if any label already exists in the table — this prevents accidental data corruption. Use `overwrite := true` to replace existing rows.\n\n**Typename → table mapping:**\n| typename | table |\n|---|---|\n| `LMFDBCliffOrd` | `clifford_orders` |\n| `LMFDBGrpSL2Cliff` | `clifford_sl2` |\n| `LMFDBGrpSL2CliffGamma0` | `clifford_gamma0` |\n| `LMFDBPSL2GrpCliffSub` | `clifford_subgroups` |\n\n## Legacy approach (pre-package-textfiles \u002F pre-package-database)\n\n**Purpose:** Serialize an LMFDB wrapper object to a pipe-delimited string, then INSERT (or\nUPDATE on conflict) directly into the appropriate `lmfdb.*` table. Shortcut for\n`\u002Flmfdb-object-to-textfile` + `\u002Ftextfile-to-database` when you don't need the DATA\u002F file.\n\n### Step 1 — Serialize to pipe string in Magma\n\n```magma\nline := SaveLMFDBObject(X);   \u002F\u002F works for any LMFDBXxx type\n```\n\nOr use the `*_ATTRS`-ordered manual serializer:\n```magma\nline := &cat[SaveAttr(attr, X``attr, X) * \"|\" : attr in LMFDBCliffOrd_ATTRS];\nline := line[1..#line-1];  \u002F\u002F strip trailing pipe\n```\n\n### Step 2 — Write the pipe string to a temp file\n\n```magma\nprint_file(\"\u002Ftmp\u002Flmfdb_obj.txt\", line: overwrite := true);\n```\n\n### Step 3 — Load into the database via Python\n\nUse `db_load.py` pointed at a single-file temp directory, or use the Python helper below.\n\n**Option A — db_load.py (recommended for batches):**\n```bash\nmkdir -p \u002Ftmp\u002Flmfdb_insert\u002Forders\ncp \u002Ftmp\u002Flmfdb_obj.txt \u002Ftmp\u002Flmfdb_insert\u002Forders\u002F2.1\ncd magma\u002Fpython\npython3 db_load.py --data-root \u002Ftmp\u002Flmfdb_insert --only orders\npython3 db_migrate.py --action populate_ledger\npython3 db_migrate.py --action promote_to_lmfdb\n```\n\n**Option B — direct psycopg2 (for single objects):**\n\nWrite a small Python snippet using the pipe-delimited string and psycopg2's COPY:\n\n```python\nimport io, db_config\nfrom db_load import ORDERS_ATTRS, _staging_cols, _preprocess_field\n\ndef insert_lmfdb_object(pipe_line, table, attrs, source=\"manual\"):\n    conn = db_config.get_connection()\n    cols = _staging_cols(attrs)\n    fields = pipe_line.rstrip(\"\\n\").split(\"|\")\n    proc = [_preprocess_field(col, f) for col, f in zip(attrs, fields)]\n    proc += [source, \"manual\"]          # source, source_path\n    line = \"|\".join(proc) + \"\\n\"\n    buf = io.StringIO(line); buf.seek(0)\n    col_list = \", \".join(cols)\n    with conn.cursor() as cur:\n        cur.copy_expert(\n            f\"COPY {table} ({col_list}) FROM STDIN \"\n            f\"WITH (FORMAT TEXT, DELIMITER '|', NULL '\\\\N')\",\n            buf,\n        )\n    conn.commit(); conn.close()\n\n# Example: insert a single order\ninsert_lmfdb_object(line, \"staging.orders_src\", ORDERS_ATTRS)\n```\n\n### Step 4 — Promote to lmfdb schema\n\n```bash\ncd magma\u002Fpython\npython3 db_migrate.py --action populate_ledger\npython3 db_migrate.py --action promote_to_lmfdb\n```\n\n`promote_to_lmfdb` uses `ON CONFLICT (label) DO UPDATE`, so re-inserting an already-stored\nobject updates its fields in place. No duplicate entries.\n\n### Column order reference\n\nThe SELECT \u002F INSERT must use the exact `*_ATTRS` alphabetical order. The critical aliasing:\n- `order_label` in SQL ↔ `order` in Magma ATTRS (SQL reserved word)\n- Staging column is `order_label_old`; lmfdb column is `order_label`\n\n### When to use this vs. lmfdb-object-to-textfile\n\n| Use `\u002Flmfdb-object-to-database` | Use `\u002Flmfdb-object-to-textfile` |\n|----------------------------------|----------------------------------|\n| One-off updates, no file needed  | Archiving computed data to DATA\u002F |\n| After `\u002Fdatabase-update`         | After a make-*.mag script        |\n| Fast iteration during dev        | Batch generation, reproducibility|\n\n### Next step\n\nVerify with:\n```sql\nSELECT label, dimension, discriminant FROM lmfdb.clifford_orders WHERE label = '\u003Cnew_label>';\n```\n\n## When to use legacy vs. new\n\nUse `AddLMFDB` (new) for any insert or upsert that can be performed within a single Magma session — it skips the temp-file round-trip, the Python staging pipeline, and the `db_migrate.py` promotion step entirely. Fall back to the legacy approach only when working with a batch large enough to warrant `db_load.py`'s bulk COPY performance, when a staging-to-lmfdb promotion step is already part of an established pipeline, or when `AddLMFDB` is not yet available in the attached package version.\n","# lmfdb-object-to-database\n\n## Dependency check\n\n```bash\n# Discover conf: project root first, hecke fallback\nCONF=\"\"\nfor candidate in \\\n    \"$(git rev-parse --show-toplevel 2>\u002Fdev\u002Fnull)\u002Flmfdb-pipeline.conf\" \\\n    \"magma\u002Fscripts\u002Fdata-generation.conf\"; do\n  [ -f \"$candidate\" ] && { CONF=\"$candidate\"; break; }\ndone\nif [ -z \"$CONF\" ]; then\n  echo \"I'm sorry, I can't do that — no database pipeline conf found.\"\n  echo \"Run \u002Fconfigure-database (mathcity-lmfdb.configure-database) to create lmfdb-pipeline.conf at your project root.\"\n  echo \"(This conf holds your PostgreSQL and DATA_DIR settings for the LMFDB pipeline.)\"\n  exit 1\nfi\nsource \"$CONF\"\n```\n\n```magma\nZ := Integers(); Q := Rationals();\nAttachSpec(\"hecke.spec\");\nSetLMFDBRootFolder(\".\");\n\ndb := OpenDB(\"clifford_bianchi_local\");\n\n\u002F\u002F Single object insert (errors if label already exists):\nAddLMFDB(db, \"LMFDBCliffOrd\", [X]);\n\n\u002F\u002F Upsert (overwrite existing row):\nAddLMFDB(db, \"LMFDBCliffOrd\", [X] : overwrite := true);\n\n\u002F\u002F Batch insert:\nAddLMFDB(db, \"LMFDBPSL2GrpCliffSub\", subs);\n\n\u002F\u002F Generic low-level insert (Assoc-level):\nAdd(db, \"clifford_orders\", [Dictionary(X)] : overwrite := true);\n```\n\n`AddLMFDB` checks that each object has a non-empty `label` attribute before inserting. With `overwrite := false` (default), the INSERT will error if any label already exists in the table — this prevents accidental data corruption. Use `overwrite := true` to replace existing rows.\n\n**Typename → table mapping:**\n| typename | table |\n|---|---|\n| `LMFDBCliffOrd` | `clifford_orders` |\n| `LMFDBGrpSL2Cliff` | `clifford_sl2` |\n| `LMFDBGrpSL2CliffGamma0` | `clifford_gamma0` |\n| `LMFDBPSL2GrpCliffSub` | `clifford_subgroups` |\n\n## Legacy approach (pre-package-textfiles \u002F pre-package-database)\n\n**Purpose:** Serialize an LMFDB wrapper object to a pipe-delimited string, then INSERT (or\nUPDATE on conflict) directly into the appropriate `lmfdb.*` table. Shortcut for\n`\u002Flmfdb-object-to-textfile` + `\u002Ftextfile-to-database` when you don't need the DATA\u002F file.\n\n### Step 1 — Serialize to pipe string in Magma\n\n```magma\nline := SaveLMFDBObject(X);   \u002F\u002F works for any LMFDBXxx type\n```\n\nOr use the `*_ATTRS`-ordered manual serializer:\n```magma\nline := &cat[SaveAttr(attr, X``attr, X) * \"|\" : attr in LMFDBCliffOrd_ATTRS];\nline := line[1..#line-1];  \u002F\u002F strip trailing pipe\n```\n\n### Step 2 — Write the pipe string to a temp file\n\n```magma\nprint_file(\"\u002Ftmp\u002Flmfdb_obj.txt\", line: overwrite := true);\n```\n\n### Step 3 — Load into the database via Python\n\nUse `db_load.py` pointed at a single-file temp directory, or use the Python helper below.\n\n**Option A — db_load.py (recommended for batches):**\n```bash\nmkdir -p \u002Ftmp\u002Flmfdb_insert\u002Forders\ncp \u002Ftmp\u002Flmfdb_obj.txt \u002Ftmp\u002Flmfdb_insert\u002Forders\u002F2.1\ncd magma\u002Fpython\npython3 db_load.py --data-root \u002Ftmp\u002Flmfdb_insert --only orders\npython3 db_migrate.py --action populate_ledger\npython3 db_migrate.py --action promote_to_lmfdb\n```\n\n**Option B — direct psycopg2 (for single objects):**\n\nWrite a small Python snippet using the pipe-delimited string and psycopg2's COPY:\n\n```python\nimport io, db_config\nfrom db_load import ORDERS_ATTRS, _staging_cols, _preprocess_field\n\ndef insert_lmfdb_object(pipe_line, table, attrs, source=\"manual\"):\n    conn = db_config.get_connection()\n    cols = _staging_cols(attrs)\n    fields = pipe_line.rstrip(\"\\n\").split(\"|\")\n    proc = [_preprocess_field(col, f) for col, f in zip(attrs, fields)]\n    proc += [source, \"manual\"]          # source, source_path\n    line = \"|\".join(proc) + \"\\n\"\n    buf = io.StringIO(line); buf.seek(0)\n    col_list = \", \".join(cols)\n    with conn.cursor() as cur:\n        cur.copy_expert(\n            f\"COPY {table} ({col_list}) FROM STDIN \"\n            f\"WITH (FORMAT TEXT, DELIMITER '|', NULL '\\\\N')\",\n            buf,\n        )\n    conn.commit(); conn.close()\n\n# Example: insert a single order\ninsert_lmfdb_object(line, \"staging.orders_src\", ORDERS_ATTRS)\n```\n\n### Step 4 — Promote to lmfdb schema\n\n```bash\ncd magma\u002Fpython\npython3 db_migrate.py --action populate_ledger\npython3 db_migrate.py --action promote_to_lmfdb\n```\n\n`promote_to_lmfdb` uses `ON CONFLICT (label) DO UPDATE`, so re-inserting an already-stored\nobject updates its fields in place. No duplicate entries.\n\n### Column order reference\n\nThe SELECT \u002F INSERT must use the exact `*_ATTRS` alphabetical order. The critical aliasing:\n- `order_label` in SQL ↔ `order` in Magma ATTRS (SQL reserved word)\n- Staging column is `order_label_old`; lmfdb column is `order_label`\n\n### When to use this vs. lmfdb-object-to-textfile\n\n| Use `\u002Flmfdb-object-to-database` | Use `\u002Flmfdb-object-to-textfile` |\n|----------------------------------|----------------------------------|\n| One-off updates, no file needed  | Archiving computed data to DATA\u002F |\n| After `\u002Fdatabase-update`         | After a make-*.mag script        |\n| Fast iteration during dev        | Batch generation, reproducibility|\n\n### Next step\n\nVerify with:\n```sql\nSELECT label, dimension, discriminant FROM lmfdb.clifford_orders WHERE label = '\u003Cnew_label>';\n```\n\n## When to use legacy vs. new\n\nUse `AddLMFDB` (new) for any insert or upsert that can be performed within a single Magma session — it skips the temp-file round-trip, the Python staging pipeline, and the `db_migrate.py` promotion step entirely. Fall back to the legacy approach only when working with a batch large enough to warrant `db_load.py`'s bulk COPY performance, when a staging-to-lmfdb promotion step is already part of an established pipeline, or when `AddLMFDB` is not yet available in the attached package version.\n",{"name":5,"description":7},"main","8d13efb5e66306aeae6e3b948bc463e7e2db1b65","skills\u002Flmfdb-object-to-database","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public","https:\u002F\u002Fgithub.com\u002Ftdupu","https:\u002F\u002Ftdupu.github.io\u002Findex.html","Associate Professor, Department of Mathematics and Statistics, University of Vermont --- last updated Fall 2019","2026-11-13 09:07:19",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add tdupu\u002Fagent-skills-public --skill lmfdb-object-to-database",{"tool":38,"command":39},"bunx","bunx skills add tdupu\u002Fagent-skills-public --skill lmfdb-object-to-database",{"tool":41,"command":42},"pnpm","pnpm dlx skills add tdupu\u002Fagent-skills-public --skill lmfdb-object-to-database","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fskills\u002Flmfdb-object-to-database\u002FSKILL.md",true,[],[47,54,61,68,75,82],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M7EW4PT586KKE7VRCAD80Z9K","writing-skills","Use when creating new skills, editing existing skills, or verifying skills work before deployment","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fsuperpowers\u002Fskills\u002Fwriting-skills\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M7EW4HV5V74AF3PTV8N4T0PS","writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fsuperpowers\u002Fskills\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M7EW4DNKGP5CR1RAJP2J9PHA","verification-before-completion","Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fsuperpowers\u002Fskills\u002Fverification-before-completion\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7EW4BA2QP88VBFVXDVJM7XQ","using-superpowers","Use when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fsuperpowers\u002Fskills\u002Fusing-superpowers\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7EW47F2JG5FBESDJNP3PKMV","using-git-worktrees","Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fsuperpowers\u002Fskills\u002Fusing-git-worktrees\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7EW44N8556Y556NX9HJT4KP","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002Ftdupu\u002Fagent-skills-public\u002Fblob\u002Fmain\u002Fsuperpowers\u002Fskills\u002Ftest-driven-development\u002FSKILL.md",[],[]]