Make open source

This commit is contained in:
John Lees-Miller
2018-10-27 16:46:26 +01:00
commit 6e82ba528b
163 changed files with 3912 additions and 0 deletions

View File

@ -0,0 +1,10 @@
class CreateGuests < ActiveRecord::Migration[5.1]
def change
create_table :guests do |t|
t.string :name
t.string :email
t.timestamps
end
end
end

View File

@ -0,0 +1,43 @@
# frozen_string_literal: true
class DeviseCreateAdminUsers < ActiveRecord::Migration[5.1]
def change # rubocop:disable Metrics/MethodLength
create_table :admin_users do |t|
## Database authenticatable
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.inet :current_sign_in_ip
t.inet :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :admin_users, :email, unique: true
add_index :admin_users, :reset_password_token, unique: true
# add_index :admin_users, :confirmation_token, unique: true
# add_index :admin_users, :unlock_token, unique: true
end
end

View File

@ -0,0 +1,16 @@
class CreateActiveAdminComments < ActiveRecord::Migration::Current
def self.up
create_table :active_admin_comments do |t|
t.string :namespace
t.text :body
t.references :resource, polymorphic: true
t.references :author, polymorphic: true
t.timestamps
end
add_index :active_admin_comments, [:namespace]
end
def self.down
drop_table :active_admin_comments
end
end

View File

@ -0,0 +1,15 @@
class AddGuestInfo < ActiveRecord::Migration[5.1]
def change
enable_extension('citext')
change_table :guests do |t|
t.change :email, :citext, null: false
t.index :email, unique: true
t.string :token, null: false
t.boolean :attending
t.integer :diet
t.string :other_diet
end
end
end

View File

@ -0,0 +1,13 @@
class CreatePlusOnes < ActiveRecord::Migration[5.1]
def change
create_table :plus_ones do |t|
t.references :guest, foreign_key: true
t.string :name
t.integer :diet
t.string :other_diet
t.boolean :child
t.timestamps
end
end
end

View File

@ -0,0 +1,14 @@
class SimplifyDiet < ActiveRecord::Migration[5.1]
def change
change_table :guests do |t|
t.remove :other_diet
t.change :diet, :string
t.string :songs
end
change_table :plus_ones do |t|
t.remove :other_diet
t.change :diet, :string
end
end
end

View File

@ -0,0 +1,7 @@
class AddGuestNotes < ActiveRecord::Migration[5.1]
def change
change_table :guests do |t|
t.string :notes
end
end
end

View File

@ -0,0 +1,9 @@
class AddFirstNameLastNameToGuest < ActiveRecord::Migration[5.1]
def change
change_table :guests do |t|
t.remove :name
t.string :first_name
t.string :last_name
end
end
end

View File

@ -0,0 +1,9 @@
class AddFirstNameLastNameToPlusOne < ActiveRecord::Migration[5.1]
def change
change_table :plus_ones do |t|
t.remove :name
t.string :first_name
t.string :last_name
end
end
end

View File

@ -0,0 +1,7 @@
class AddConfirmedAtToGuests < ActiveRecord::Migration[5.1]
def change
change_table :guests do |t|
t.datetime :confirmed_at
end
end
end

View File

@ -0,0 +1,5 @@
class CreateAttendees < ActiveRecord::Migration[5.1]
def change
create_view :attendees
end
end

105
db/schema.rb Normal file
View File

@ -0,0 +1,105 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180804103058) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "citext"
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace"
t.text "body"
t.string "resource_type"
t.bigint "resource_id"
t.string "author_type"
t.bigint "author_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
t.index ["namespace"], name: "index_active_admin_comments_on_namespace"
t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
end
create_table "admin_users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_admin_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end
create_table "guests", force: :cascade do |t|
t.citext "email", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "token", null: false
t.boolean "attending"
t.string "diet"
t.string "songs"
t.string "notes"
t.string "first_name"
t.string "last_name"
t.datetime "confirmed_at"
t.index ["email"], name: "index_guests_on_email", unique: true
end
create_table "plus_ones", force: :cascade do |t|
t.bigint "guest_id"
t.string "diet"
t.boolean "child"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "first_name"
t.string "last_name"
t.index ["guest_id"], name: "index_plus_ones_on_guest_id"
end
add_foreign_key "plus_ones", "guests"
create_view "attendees", sql_definition: <<-SQL
SELECT (guests.id)::text AS id,
guests.first_name,
guests.last_name,
guests.email,
guests.diet,
guests.songs,
guests.notes,
NULL::boolean AS child,
guests.updated_at
FROM guests
WHERE guests.attending
UNION ALL
SELECT ((plus_ones.guest_id || '-'::text) || plus_ones.id) AS id,
plus_ones.first_name,
plus_ones.last_name,
NULL::citext AS email,
plus_ones.diet,
NULL::character varying AS songs,
NULL::character varying AS notes,
plus_ones.child,
plus_ones.updated_at
FROM (plus_ones
JOIN guests ON ((plus_ones.guest_id = guests.id)))
WHERE guests.attending;
SQL
end

21
db/seeds.rb Normal file
View File

@ -0,0 +1,21 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
if AdminUser.count.zero?
email = 'admin@example.com'
password = SecureRandom.hex
AdminUser.create!(
email: email,
password: password,
password_confirmation: password
)
puts "Admin user email: #{email}"
puts "Admin user password: #{password}"
end

View File

@ -0,0 +1,18 @@
SELECT
id::text,
first_name, last_name, email,
diet, songs, notes, NULL as child,
updated_at
FROM guests
WHERE attending
UNION ALL
SELECT
guest_id || '-' || plus_ones.id AS id,
plus_ones.first_name, plus_ones.last_name, NULL AS email,
plus_ones.diet, NULL as songs, NULL as notes, plus_ones.child,
plus_ones.updated_at
FROM plus_ones
JOIN guests ON plus_ones.guest_id = guests.id
WHERE guests.attending