From f93f90868309197ae6452d2c429d80015add36f1 Mon Sep 17 00:00:00 2001 From: swaggboi Date: Wed, 22 Nov 2023 23:21:19 -0500 Subject: [PATCH] Some migrations plumbing --- BLOG.md | 71 +++++++++++++++++++++++++ README.md | 10 ++++ bin/pastes-bin | 14 +++++ lib/Pastes-Bin.rakumod | 27 ++++++++++ lib/Pastes-Bin/Controller/Paste.rakumod | 0 lib/Pastes-Bin/Model/Paste.rakumod | 0 6 files changed, 122 insertions(+) create mode 100755 bin/pastes-bin create mode 100644 lib/Pastes-Bin.rakumod create mode 100644 lib/Pastes-Bin/Controller/Paste.rakumod create mode 100644 lib/Pastes-Bin/Model/Paste.rakumod diff --git a/BLOG.md b/BLOG.md index b2e6b50..74ee492 100644 --- a/BLOG.md +++ b/BLOG.md @@ -10,3 +10,74 @@ All migrations go into a single file I'll creatively call `migrations`: -- 1 down DROP TABLE pastes; + +Connect to the database and then apply the migrations: + + my $dbh = DBIish.connect: + 'Pg', + :host, + :database, + :user, + password => prompt 'enter DB password: '; + + my $m = DB::Migration::Simple.new: + :$dbh, + :migration-file; + + $m.migrate: :version<1>; + +Get prompted for password for now: + + $ ./bin/pastes-bin + enter DB password: hogrider69 + line: -- 1 up + version: 1, direction: up + line: CREATE TABLE IF NOT EXISTS pastes ( + line: paste_id SERIAL PRIMARY KEY, + line: paste_body TEXT + line: ); + line: -- 1 down + version: 1, direction: down + line: DROP TABLE pastes; + initializing db-migrations-simple-meta + set initial version to 0 + {1 => {down => DROP TABLE pastes; + , up => CREATE TABLE IF NOT EXISTS pastes ( + paste_id SERIAL PRIMARY KEY, + paste_body TEXT + ); + }} + migrating from version '0' to version '1' + True migrating 'up' from version '0' to version '1' + doing 'up' migrations for 1 + executing CREATE TABLE IF NOT EXISTS pastes ( + paste_id SERIAL PRIMARY KEY, + paste_body TEXT + ) + Humming-Bird listening on port http://localhost:3000 + +Let's check on DB: + + $ psql -h devbussy.swagg.net -U pastes_bin + Password for user pastes_bin: + psql (15.3 (Debian 15.3-0+deb12u1)) + SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off) + Type "help" for help. + + pastes_bin=> \d + List of relations + Schema | Name | Type | Owner + --------+---------------------------+----------+------------ + public | db-migrations-simple-meta | table | pastes_bin + public | pastes | table | pastes_bin + public | pastes_paste_id_seq | sequence | pastes_bin + (3 rows) + + pastes_bin=> \d pastes; + Table "public.pastes" + Column | Type | Collation | Nullable | Default + ------------+---------+-----------+----------+------------------------------------------ + paste_id | integer | | not null | nextval('pastes_paste_id_seq'::regclass) + paste_body | text | | | + Indexes: + "pastes_pkey" PRIMARY KEY, btree (paste_id) diff --git a/README.md b/README.md index 44c57c3..fa2cf67 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,13 @@ ## Pastes-Bin Paste welcomes you to his bin: Paste's Bin + +## Run Locally + +### Install Dependencies + + zef -v install --deps-only . + +### Run Doink + + ./bin/pastes-bin diff --git a/bin/pastes-bin b/bin/pastes-bin new file mode 100755 index 0000000..5f84a7d --- /dev/null +++ b/bin/pastes-bin @@ -0,0 +1,14 @@ +#!/usr/bin/env raku + +# It is important that you import App::MyService after +# Humming-Bird::Core to avoid having some weird side-effects with +# route declarations in your service + +use v6.d; +use Humming-Bird::Core; + +# Local libs +use lib 'lib'; +use Pastes-Bin; + +listen 3000; diff --git a/lib/Pastes-Bin.rakumod b/lib/Pastes-Bin.rakumod new file mode 100644 index 0000000..dfa929d --- /dev/null +++ b/lib/Pastes-Bin.rakumod @@ -0,0 +1,27 @@ +use Humming-Bird::Core; +use Humming-Bird::Middleware; +use Humming-Bird::Advice; +use DB::Migration::Simple; +use DBIish; + +# Local libs +#use Pastes-Bin::Controller::Paste; # Coming soon! + +# Logging +middleware &middleware-logger; +advice &advice-logger; + +# Database stuff +my $dbh = DBIish.connect: + 'Pg', + :host, + :database, + :user, + password => prompt 'enter DB password: '; + +my $m = DB::Migration::Simple.new: + :$dbh, + :migration-file, + :verbose; + +$m.migrate: :version<1>; diff --git a/lib/Pastes-Bin/Controller/Paste.rakumod b/lib/Pastes-Bin/Controller/Paste.rakumod new file mode 100644 index 0000000..e69de29 diff --git a/lib/Pastes-Bin/Model/Paste.rakumod b/lib/Pastes-Bin/Model/Paste.rakumod new file mode 100644 index 0000000..e69de29