{"library":"sqlite-migrate","title":"SQLite Migrate","type":"library","description":"sqlite-migrate is a simple database migration system for SQLite, built upon the sqlite-utils library. It allows users to define database schema changes and data manipulations as Python functions within numbered files, which can then be applied incrementally. The current version is 0.1b0, with releases occurring periodically to address bugs and introduce new features during its beta phase.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install sqlite-migrate"],"cli":{"name":"sqlite-migrate","version":"sh: 1: sqlite-migrate: not found"}},"imports":["from sqlite_migrate import Migrations","from sqlite_migrate import MigrationSet"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://sqlite-migrate.datasette.io","github":"https://github.com/simonw/sqlite-migrate","docs":null,"changelog":"https://github.com/simonw/sqlite-migrate/releases","pypi":"https://pypi.org/project/sqlite-migrate/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import sqlite_utils\nfrom sqlite_migrate import Migrations\nimport os\n\n# 1. Prepare a temporary database file\ndb_path = \"quickstart.db\"\nif os.path.exists(db_path):\n    os.remove(db_path)\ndb = sqlite_utils.Database(db_path)\n\n# 2. Define a migration in a temporary directory\nmigrations_dir = \"./qs_migrations\"\nos.makedirs(migrations_dir, exist_ok=True)\nmigration_file_path = os.path.join(migrations_dir, \"001_create_users_table.py\")\n\nwith open(migration_file_path, \"w\") as f:\n    f.write(\"\"\"\ndef migrate(db):\n    db[\"users\"].create({\"id\": int, \"name\": str}, pk=\"id\", if_not_exists=True)\n    db[\"users\"].insert({\"id\": 1, \"name\": \"Alice\"})\n\"\"\")\n\n# 3. Initialize Migrations and apply them\nmigrations = Migrations(db, [migrations_dir])\nmigrations.apply()\n\nprint(f\"Database '{db_path}' migrated successfully.\")\nprint(f\"Tables: {db.table_names()}\")\nprint(f\"Users count: {db['users'].count()}\")\n\n# 4. Clean up temporary files\nos.remove(migration_file_path)\nos.rmdir(migrations_dir)\nos.remove(db_path)","lang":"python","description":"This quickstart demonstrates how to create a simple migration, apply it to an SQLite database, and verify the changes. It involves creating a temporary migration file and directory, then using the `Migrations` class to execute the migration.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}