You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce a first-class workflow for importing existing PostgreSQL projects into PostKit. Currently, postkit init assumes a greenfield project — there is no way to onboard a database that already has tables, indexes, constraints, and data. Teams evaluating PostKit must be able to adopt it incrementally without rebuilding their schema from scratch.
Motivation
User Story
As a developer with an existing PostgreSQL project, I want to import my database into PostKit so that I can start using PostKit's migration workflow for future changes, without losing or recreating my current schema.
Current Pain Points
No import path — postkit init creates empty state files (committed.json: {}, empty schema.sql). Pointing it at an existing database does nothing.
Manual baseline is error-prone — Users must manually pg_dump their schema, place it in the right directory, and hand-craft committed.json to match. Any mismatch causes db plan to generate a full-drop-and-recreate plan.
No documentation — There are zero docs describing how to bring an existing project under PostKit management.
Import an existing PostgreSQL database into PostKit by creating a baseline snapshot.
Options
Flag
Description
Default
--url <string>
Database URL to import from
Uses localDbUrl from config
--schema <string>
PostgreSQL schema to import
public
--name <string>
Label for the baseline migration
"imported_baseline"
--skip-data
Only import schema, ignore seed data
false
--dry-run
Preview what would be imported without writing
false
Behavior
# Typical usage — import an existing database
postkit db import --url "postgres://user:pass@host:5432/existing_db"# Preview first
postkit db import --url "postgres://user:pass@host:5432/existing_db" --dry-run
# Import a specific schema
postkit db import --url "postgres://..." --schema app_schema --name "v2_baseline"
Step-by-Step Flow
┌─────────────────────────────────────────────┐
│ 1. Validate & Connect │
│ • Verify target database is reachable │
│ • Check no active PostKit session exists │
│ • Warn if .postkit/ state already exists │
├─────────────────────────────────────────────┤
│ 2. Dump Schema │
│ • pg_dump --schema-only (filtered) │
│ • Separate infra statements (roles, │
│ extensions, schemas) into schema/infra/ │
│ • Write table DDL to schema/schema.sql │
│ • Extract GRANT statements → schema/grants/│
├─────────────────────────────────────────────┤
│ 3. Create Baseline Migration │
│ • Generate timestamped migration file │
│ (e.g. 20260408120000_imported_baseline) │
│ • Migration contains full CREATE TABLE │
│ statements with -- migrate:up / down │
│ • Place in .postkit/db/migrations/ │
├─────────────────────────────────────────────┤
│ 4. Initialize State │
│ • Set committed.json with baseline │
│ migration recorded as applied │
│ • Set .postkit/db/schema.sql snapshot │
│ • Mark session as idle (no active session)│
├─────────────────────────────────────────────┤
│ 5. Optional: Capture Seed Data │
│ • If --skip-data is false, dump table │
│ row counts and sample data to │
│ schema/seeds/ │
├─────────────────────────────────────────────┤
│ 6. Report │
│ • Tables imported: N │
│ • Indexes: N │
│ • Foreign keys: N │
│ • Migration file: .postkit/db/migrations/│
│ 20260408120000_imported_baseline.sql │
│ • Next step: postkit db start │
└─────────────────────────────────────────────┘
Technical Design
1. Schema Introspection
Use pg_dump --schema-only --no-owner --no-privileges to extract DDL, then parse the output to categorize statements:
Category
Destination
CREATE TABLE, indexes, constraints, triggers
schema/schema.sql
CREATE EXTENSION, CREATE SCHEMA, role DDL
schema/infra/
GRANT / REVOKE
schema/grants/
2. Baseline Migration File
-- Migration: imported_baseline-- Created: 2026-04-08T12:00:00Z-- Source: postgres://user:***@host:5432/existing_db-- This is an auto-generated baseline from an existing database.-- migrate:upCREATETABLEIF NOT EXISTS users (
id SERIALPRIMARY KEY,
email varchar(255) NOT NULL,
...
);
-- ... all other tables ...-- migrate:down-- (intentionally empty — baseline cannot be reversed)
How to configure remotes for deployment after import
Troubleshooting common import issues
2. Update: README.md
Add import command to the usage section:
# Import an existing database into PostKit
postkit db import --url "postgres://user:pass@host:5432/myapp"
Add to the DB Module command table:
Command
Description
postkit db import
Import existing database into PostKit
3. Update: Quick Start Guide
Add an alternative path for existing projects:
# For existing projects with a database:
postkit db import --url "postgres://user:pass@host:5432/existing_db"
postkit db remote add staging "postgres://user:pass@staging-host:5432/myapp"
postkit db start # Ready to make changes!
4. Update: Configuration Docs
Document the importedFrom field in committed.json and how it affects state tracking.
5. Update: DB Module Overview
Add db import to the command reference with full option documentation.
Out of Scope (Future Work)
Incremental import — Importing only specific tables/schemas (use --schema for now)
Migration from other tools — Converting Flyway/Liquibase/Prisma migration history
Data migration — Moving actual row data between databases (use db seed separately)
Reverse migration — Generating migrate:down SQL for the baseline
Multi-schema import — Importing multiple PostgreSQL schemas in one command
Priority Justification
High priority because:
This is the most common onboarding question for new users
Without it, PostKit is only usable for greenfield projects — a very small market
The feature is well-scoped and does not require architectural changes
It directly impacts adoption and evaluation of PostKit
Summary
Introduce a first-class workflow for importing existing PostgreSQL projects into PostKit. Currently,
postkit initassumes a greenfield project — there is no way to onboard a database that already has tables, indexes, constraints, and data. Teams evaluating PostKit must be able to adopt it incrementally without rebuilding their schema from scratch.Motivation
User Story
Current Pain Points
postkit initcreates empty state files (committed.json: {}, emptyschema.sql). Pointing it at an existing database does nothing.pg_dumptheir schema, place it in the right directory, and hand-craftcommitted.jsonto match. Any mismatch causesdb planto generate a full-drop-and-recreate plan.Proposed Solution
New Command:
postkit db importImport an existing PostgreSQL database into PostKit by creating a baseline snapshot.
Options
--url <string>localDbUrlfrom config--schema <string>public--name <string>"imported_baseline"--skip-datafalse--dry-runfalseBehavior
Step-by-Step Flow
Technical Design
1. Schema Introspection
Use
pg_dump --schema-only --no-owner --no-privilegesto extract DDL, then parse the output to categorize statements:CREATE TABLE, indexes, constraints, triggersschema/schema.sqlCREATE EXTENSION,CREATE SCHEMA, role DDLschema/infra/GRANT/REVOKEschema/grants/2. Baseline Migration File
3. State Initialization
{ "migrations": [ { "id": "20260408120000", "name": "imported_baseline", "appliedAt": "2026-04-08T12:00:00.000Z", "checksum": "sha256:abc123...", "source": "import", "tables": ["users", "categories", "products", "..."] } ], "importedFrom": { "url": "postgres://user:***@host:5432/existing_db", "importedAt": "2026-04-08T12:00:00.000Z", "schemaCount": 14, "version": "1.0.5" } }4. Edge Cases
.postkit/already exists with statepostkit db import --forceto overwrite.".postkit/exists but empty/corruptpostkit db commitorpostkit db abortfirst."postkit initfor a new project."--dry-runflag5. Config Generation
If
postkit.config.jsondoes not exist, auto-generate it:{ "db": { "localDbUrl": "<imported-url>", "schemaPath": "schema", "schema": "public", "remotes": {} } }Acceptance Criteria
postkit db import --url <url>successfully imports an existing databaseschema/schema.sqlmatches the source database DDL.postkit/db/migrations/committed.jsoncorrectly records the baseline as appliedpostkit db planproduces an empty diff (no changes)postkit db start→db plan→db apply→db commitworkflow works after import--dry-runpreviews import without side effects.postkit/state is protected (abort or--force)Documentation Updates Required
1. New Section: "Migrating an Existing Project"
Location:
docs/getting-started/migrating-to-postkit.mdContent should cover:
postkit db importvspostkit init2. Update: README.md
Add import command to the usage section:
Add to the DB Module command table:
postkit db import3. Update: Quick Start Guide
Add an alternative path for existing projects:
4. Update: Configuration Docs
Document the
importedFromfield incommitted.jsonand how it affects state tracking.5. Update: DB Module Overview
Add
db importto the command reference with full option documentation.Out of Scope (Future Work)
--schemafor now)db seedseparately)migrate:downSQL for the baselinePriority Justification
High priority because:
Estimated Effort
--dry-runmode