{"id":22491770,"url":"https://github.com/travishorn/libsql-migrate","last_synced_at":"2025-03-27T20:23:48.849Z","repository":{"id":228657356,"uuid":"774170738","full_name":"travishorn/libsql-migrate","owner":"travishorn","description":"Database migration and seed management for libsql with configurable options.","archived":false,"fork":false,"pushed_at":"2024-04-11T15:14:46.000Z","size":301,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T12:28:18.841Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/travishorn.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}},"created_at":"2024-03-19T04:14:40.000Z","updated_at":"2024-05-22T17:48:36.000Z","dependencies_parsed_at":"2024-03-19T21:29:45.620Z","dependency_job_id":"525b0e8f-84d8-47c5-9311-1fdb2e191d97","html_url":"https://github.com/travishorn/libsql-migrate","commit_stats":null,"previous_names":["travishorn/libsql-migrate"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Flibsql-migrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Flibsql-migrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Flibsql-migrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travishorn%2Flibsql-migrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/travishorn","download_url":"https://codeload.github.com/travishorn/libsql-migrate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245917785,"owners_count":20693590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-12-06T18:10:13.793Z","updated_at":"2025-03-27T20:23:48.822Z","avatar_url":"https://github.com/travishorn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libsql Migrate\n\nDatabase migration and seed management for libsql with configurable options.\n\n## Installation\n\nThe easiest method is a global installation.\n\n```sh\nnpm install -g libsql-migrate\n```\n\nThe `libsql-migrate` command is now available for your usage.\n\n### Local installation\n\nInstead of installing globally, you can install locally to your project.\n\n```sh\nnpm install --save-dev libsql-migrate\n```\n\nThis prevents compatibility issues because it defines the version of\n`libsql-migrate` that the migrations/seeds in your repository were written for.\n\nYou can either run `npx libsql-migrate \u003ccommand\u003e` and/or add migration commands\nto your `package.json`:\n\n```json\n{\n  \"name\": \"mypackage\",\n  \"version\": \"0.1.0\",\n  \"scripts\": {\n    \"migrate\": \"libsql-migrate latest\",\n    \"seed\": \"libsql-migrate seed:run\"\n  }\n}\n```\n\n## Usage\n\n1. Navigate to your project's root directory.\n\n```sh\ncd my/project/root\n```\n\n2. Create a fresh libsql-migrate configuration file.\n\n```sh\nlibsql-migrate init\n```\n\n3. This writes a file called `libsqlrc.js` with the following contents. Modify it\n   to meet your project's configuration.\n\n```javascript\nexport default {\n  development: {\n    connection: {\n      url: \"file:local.db\",\n    },\n  },\n  production: {\n    connection: {\n      url: \"libsql://...\",\n      authToken: \"...\",\n    },\n  },\n};\n```\n\n### Make a new migration\n\n1. Make a new migration named `demo`.\n\n```sh\nlibsql-migrate make demo\n```\n\nReplace `demo` with whatever name you'd like to give the migration.\n\nA file with the current timestamp and the name you chose will be written to the\nmigrations directory. This directory is `./migrations` by default, but can be\nconfigured in `libsqlrc.js` like so:\n\n```javascript\nexport default {\n  development: {\n    connection: {\n      url: \"file:local.db\",\n    },\n    migrations: {\n      directory: \"my_migrations_directory\",\n    },\n  },\n  // ...\n};\n```\n\nMigration files look like this:\n\n```javascript\nexport async function up(client) {}\n\nexport async function down(client) {}\n```\n\n2. Write the code that brings your schema **up** toward the latest version in the\n   `up()` function. For example:\n\n```javascript\nexport async function up(client) {\n  await client.execute(\n    \"CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);\",\n  );\n}\n```\n\n3. Write the code that reverts your schema **down** in the `down()` function:\n\n```javascript\nexport async function down(client) {\n  await client.execute(\"DROP TABLE users;\");\n}\n```\n\n### Run the next migration\n\nRun the next migration that has not yet been run.\n\n```sh\nlibsql-migrate up\n```\n\nThe `up()` function in the next migration file (alphabetically) in the migration\ndirectory will be executed.\n\nYou can repeatedly run this command to keep migrating up. If you want to run all\npending migrations to bring the database schema fully up-to-date, use the\n[`latest`](#latest) command.\n\n### Roll back the latest migration\n\nRoll back the latest migration that was run.\n\n```sh\nlibsql-migrate down\n```\n\nThe `down()` function in the most recently executed migration file will be\nexecuted.\n\nYou can repeatedly run this command to roll back the database schema further and\nfurther back.\n\n### Run all pending migrations\n\nRun all migrations that have not yet been run.\n\n```sh\nlibsql-migrate latest\n```\n\nThe `up()` function for all pending migration files will be executed in series.\nAll migrations that were run during this command are considered part of the same\n\"batch\".\n\n### Roll back the latest batch\n\nRoll back all migrations that were run during the last batch.\n\n```sh\nlibsql-migrate rollback\n```\n\nThe `down()` function for all migrations that were run in the last batch will be\nexecuted in series. This is useful to roll back all changes from a\n`libsql-migrate latest` command.\n\nYou can repeatedly run this command to roll back subsequent batches.\n\n### Make a new seed\n\n1. Generate a new seed file.\n\n```sh\nlibsql-migrate seed:make demo\n```\n\nReplace `demo` with whatever name you'd like to give the seed.\n\nA file with the name you chose will be written to the seeds directory. This\ndirectory is `./seeds` by default, but can be configured in `libsqlrc.js` like\nso:\n\n```javascript\nexport default {\n  development: {\n    connection: {\n      url: \"file:local.db\",\n    },\n    seeds: {\n      directory: \"my_seeds_directory\",\n    },\n  },\n  // ...\n};\n```\n\nSeed files look like this:\n\n```javascript\nexport async function seed(client) {}\n```\n\n2. Write the code that seeds your database with preset data in the `seed()`\n   function. Note that you'll probably want to delete old data before seeding.\n\nFor example:\n\n```javascript\nexport async function seed(client) {\n  await client.execute(\"DELETE FROM users;\");\n  await client.execute(\"INSERT INTO users (name) VALUES ('admin')\");\n}\n```\n\n### Run all seeds\n\nRun all seed files to fill the database with preset data.\n\n```sh\nlibsql-migrate seed:run\n```\n\nThis will execute the `seed()` function inside all seed files in the seeds\ndirectory. Files are executed in alphabetical order.\n\n### Run specified seed(s)\n\nInclude the name of a seed file to run it.\n\n```sh\nlibsql-migrate seed:run animals\n```\n\nThis will execute the `seed()` function inside the `animals.js` file in the\nseeds directory.\n\nInclude multiple names to run multiple seeds.\n\n```sh\nlibsql-migrate seed:run animals cars\n```\n\nThis will run both the `animals.js` and the `cars.js` seed files. Seeds are run\nin alphabetical order no matter which order they are provided to the CLI.\n\n## Development\n\nYou can clone this project via git and make changes that fit your application.\n\n1. Clone this repository.\n\n```sh\ngit clone https://github.com/travishorn/libsql-migrate\n```\n\n2. Change into the cloned repository's directory.\n\n```sh\ncd libsql-migrate\n```\n\n3. Install dependencies.\n\n```sh\nnpm install\n```\n\n4. (Optional) Install the CLI globally.\n\n```sh\nnpm install -g .\n```\n\nThe `libsql-migrate` command is now available globally for your usage.\n\n## Contributing\n\nContributions are welcome. Kindly run `npm run format` and `npm run lint` before\ncommitting code and submitting a pull request.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright © 2024 Travis Horn\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the “Software”), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravishorn%2Flibsql-migrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftravishorn%2Flibsql-migrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravishorn%2Flibsql-migrate/lists"}