trekker

Crates.iotrekker
lib.rstrekker
version0.2.2
sourcesrc
created_at2023-10-15 00:27:44.248383
updated_at2023-10-15 00:27:44.248383
descriptionA command line tool to help you manage your PostgreSQL database migrations and seeds.
homepage
repository
max_upload_size
id1003361
size35,337
Caige Nichols (caiges)

documentation

README

Trekker

Manage database migrations and seeds. Trekker is an incredibly specific tool used to migrate and seed databases. It does this in a very simplistic manner and I'd be surprised if I ever make it do more. I use it in my workflows and it's useful for me.

Usage

Install

cargo install trekker

Connecting

Trekker uses the DATABASE_URL variable to connect to your Postgres database.

Migrations

Trekker expects that you'll keep migrations in a particular directory.

Writing a migration entails creating a file, db/migrations/001-add-reddit-subreddits.sql, with the migration SQL:

create table if not exists subreddits (
  id serial primary key,
  subreddit varchar not null unique
);

I use a three digit padded prefix to control execution order but you could also use a timestamp or date.

To run all of the migrations, use the migrate command:

trekker migrate db/migrations

Seeds

Trekker expects that you'll keep seeds in a particular directory.

Writing a seed entails creating a file, db/seeds/001-add-some-subreddits.sql, with the seed SQL:

insert into subreddits (subreddit) values
  ('mechmarket'),
  ('hardwareswap')
;

I use a three digit padded prefix to control execution order but you could also use a timestamp or date.

To run all of the seeds, use the seed command:

trekker seed db/seeds
Commit count: 0

cargo fmt