{"id":35794216,"url":"https://github.com/elitan/terradb","last_synced_at":"2026-01-17T17:38:29.423Z","repository":{"id":297872552,"uuid":"997521892","full_name":"elitan/terradb","owner":"elitan","description":"Declarative schema management for PostgreSQL and SQLite.","archived":false,"fork":false,"pushed_at":"2026-01-13T20:57:58.000Z","size":2070,"stargazers_count":16,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T20:58:25.500Z","etag":null,"topics":["database","migrations","postgres","postgresql"],"latest_commit_sha":null,"homepage":"https://pgterra.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elitan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-06T17:10:44.000Z","updated_at":"2026-01-13T20:58:03.000Z","dependencies_parsed_at":"2025-06-08T03:23:23.157Z","dependency_job_id":"d5db18db-b15c-41e9-bac8-3ca2783a9e2d","html_url":"https://github.com/elitan/terradb","commit_stats":null,"previous_names":["elitan/pgterra","elitan/terra","elitan/terradb"],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/elitan/terradb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elitan%2Fterradb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elitan%2Fterradb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elitan%2Fterradb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elitan%2Fterradb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elitan","download_url":"https://codeload.github.com/elitan/terradb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elitan%2Fterradb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28513782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["database","migrations","postgres","postgresql"],"created_at":"2026-01-07T09:20:58.053Z","updated_at":"2026-01-17T17:38:29.388Z","avatar_url":"https://github.com/elitan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# terradb\n\nDeclarative schema management for PostgreSQL and SQLite.\n\n## Install\n\n```bash\nnpm install -g terradb\n```\n\n## Quick Start\n\n### PostgreSQL\n\n```sql\n-- schema.sql\nCREATE TABLE users (\n  id SERIAL PRIMARY KEY,\n  email VARCHAR(255) NOT NULL UNIQUE\n);\n```\n\n```bash\nexport DATABASE_URL=\"postgres://user:password@localhost:5432/mydb\"\nterradb plan   # preview changes\nterradb apply  # apply changes\n```\n\n### SQLite\n\n```sql\n-- schema.sql\nCREATE TABLE users (\n  id INTEGER PRIMARY KEY,\n  email TEXT NOT NULL UNIQUE\n);\n```\n\n```bash\nexport DATABASE_URL=\"sqlite:///path/to/database.db\"\nterradb plan\nterradb apply\n```\n\n## How It Works\n\n1. Write your desired schema as CREATE statements\n2. Run `terradb plan` to see what changes are needed\n3. Run `terradb apply` to execute the changes\n\nterradb compares your schema file against the current database state and generates the necessary ALTER/DROP/CREATE statements.\n\n## Configuration\n\n### PostgreSQL\n\n```bash\nexport DATABASE_URL=\"postgres://user:password@localhost:5432/mydb\"\n```\n\nOr individual variables:\n\n```bash\nexport DB_HOST=localhost\nexport DB_PORT=5432\nexport DB_NAME=mydb\nexport DB_USER=postgres\nexport DB_PASSWORD=password\n```\n\n### SQLite\n\n```bash\nexport DATABASE_URL=\"sqlite:///path/to/database.db\"\n# or\nexport DATABASE_URL=\"/path/to/database.db\"\n# or in-memory\nexport DATABASE_URL=\":memory:\"\n```\n\n## Feature Support\n\n| Feature | PostgreSQL | SQLite |\n|---------|------------|--------|\n| Tables \u0026 Columns | Yes | Yes |\n| Primary Keys | Yes | Yes |\n| Foreign Keys | Yes | Yes |\n| Indexes | Yes | Yes |\n| Unique Constraints | Yes | Yes |\n| Check Constraints | Yes | Yes |\n| Views | Yes | Yes |\n| ENUM Types | Yes | No |\n| Sequences | Yes | No |\n| Functions | Yes | No |\n| Procedures | Yes | No |\n| Triggers | Yes | No |\n| Materialized Views | Yes | No |\n| Schemas | Yes | No |\n| Extensions | Yes | No |\n\nSQLite uses table recreation for schema changes that ALTER TABLE doesn't support (column type changes, constraint modifications, etc.).\n\n## Commands\n\n```bash\nterradb plan                    # Preview changes\nterradb plan -f custom.sql      # Use custom schema file\nterradb apply                   # Apply changes\nterradb apply -f custom.sql     # Apply from custom file\n```\n\n## Examples\n\n### Constraints\n\n```sql\n-- Primary keys\nid SERIAL PRIMARY KEY           -- PostgreSQL\nid INTEGER PRIMARY KEY          -- SQLite\n\n-- Foreign keys\nCONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE\n\n-- Check constraints\nCONSTRAINT check_positive CHECK (quantity \u003e 0)\n\n-- Unique constraints\nCONSTRAINT unique_email UNIQUE (email)\n```\n\n### Indexes\n\n```sql\nCREATE INDEX idx_email ON users (email);\nCREATE INDEX idx_active ON users (email) WHERE active = true;  -- partial index\nCREATE UNIQUE INDEX idx_unique_email ON users (email);\n```\n\n### PostgreSQL-only Features\n\n```sql\n-- ENUM types\nCREATE TYPE status AS ENUM ('pending', 'active', 'inactive');\n\n-- Views\nCREATE VIEW active_users AS SELECT * FROM users WHERE active = true;\nCREATE MATERIALIZED VIEW user_stats AS SELECT COUNT(*) FROM users;\n\n-- Functions\nCREATE FUNCTION add(a INT, b INT) RETURNS INT AS $$ SELECT a + b $$ LANGUAGE SQL;\n\n-- Sequences\nCREATE SEQUENCE custom_seq START 1000 INCREMENT 1;\n```\n\n## Development\n\nRequires [Bun](https://bun.sh):\n\n```bash\ngit clone https://github.com/elitan/terradb.git\ncd terradb\nbun install\n\n# PostgreSQL tests\ndocker compose up -d\nbun test\n\n# SQLite tests (no docker needed)\nbun test src/test/sqlite/\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felitan%2Fterradb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felitan%2Fterradb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felitan%2Fterradb/lists"}