Skip to content
This repository was archived by the owner on Dec 13, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:postgres@localhost/postgres
3 changes: 1 addition & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Deploy to GOV.UK PaaS

on:
push:
branches: [main]
workflow_dispatch:

env:
REGISTRY: ghcr.io
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
gem "sinatra"
gem "pry"
gem "thin"
gem "pg"
gem "sequel"
gem "dotenv"
gem "jwt"
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ GEM
specs:
coderay (1.1.3)
daemons (1.4.1)
dotenv (2.7.6)
eventmachine (1.2.7)
jwt (2.3.0)
method_source (1.0.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
pg (1.2.3)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rack (2.2.3)
rack-protection (2.1.0)
rack
ruby2_keywords (0.0.5)
sequel (5.52.0)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
Expand All @@ -29,7 +33,11 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
dotenv
jwt
pg
pry
sequel
sinatra
thin

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# CIFU Forms API Prototype

A prototype for a forms API for the collecting information from users team built with Ruby and Sinatra.

## Running the database with docker

`docker run --name db -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:13`
5 changes: 5 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV)
require_relative 'loader'
require_relative './server'

run Server
40 changes: 40 additions & 0 deletions db/database.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "sequel"

class Migrator
def initialize
Sequel.extension :migration
end

def destroy(database)
Sequel::Migrator.run(database, "#{__dir__}/migrations", target: 0)
end

def migrate(database)
Sequel::Migrator.run(database, "#{__dir__}/migrations")
end

def migrate_to(database, version)
Sequel::Migrator.run(database, "#{__dir__}/migrations", target: version)
end
end

class Database
def initialize
@migrator = Migrator.new
end

def connect
database = Sequel.connect(ENV['DATABASE_URL'])
load_extensions_for(database)

@migrator.migrate(database)
database
end

private

def load_extensions_for(database)
database.extension :pg_json
database.extension :pg_array
end
end
11 changes: 11 additions & 0 deletions db/migrations/1_add_forms_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Sequel.migration do
change do
create_table :forms do
primary_key :id, type: :Bignum
String :username
String :key
String :display_name
column :form, 'json'
end
end
end
Loading