Skip to content

Commit

Permalink
Change waydowntown to share registrations database
Browse files Browse the repository at this point in the history
This feel like a triumph 🤪
  • Loading branch information
backspace committed Jun 30, 2024
1 parent 3c2dda3 commit 9976899
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-waydowntown-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11-alpine
image: postgres:13-alpine
ports:
- "5432:5432"
env:
Expand Down
4 changes: 4 additions & 0 deletions registrations/lib/dump-waydowntown-server-schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cd ../waydowntown/waydowntown_server
bundle exec rake db:schema:dump
bundle exec rubocop -A db/schema.rb > /dev/null
echo "waydowntown server schema dumped successfully"
6 changes: 4 additions & 2 deletions registrations/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ defmodule Registrations.Mixfile do
"ecto.reset": ["ecto.drop", "ecto.setup"],
"db.migrate": [
"ecto.migrate",
"ecto.dump -d ../unmnemonic_devices_vrs/tests/fixtures/schema.sql"
"ecto.dump -d ../unmnemonic_devices_vrs/tests/fixtures/schema.sql",
"cmd ./lib/dump-waydowntown-server-schema.sh"
],
"db.rollback": [
"ecto.rollback",
"ecto.dump -d ../unmnemonic_devices_vrs/tests/fixtures/schema.sql"
"ecto.dump -d ../unmnemonic_devices_vrs/tests/fixtures/schema.sql",
"cmd ./lib/dump-waydowntown-server-schema.sh"
],
test: ["ecto.create --quiet", "ecto.migrate", "test"]
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Registrations.Repo.Migrations.AddWaydowntownSchema do
use Ecto.Migration

def up do
execute("CREATE SCHEMA waydowntown")
end

def down do
execute("DROP SCHEMA waydowntown")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Registrations.Repo.Migrations.AddWaydowntownIncarnations do
use Ecto.Migration

def change do
create table(:incarnations, prefix: "waydowntown", primary_key: false) do
add(:id, :uuid, primary_key: true, default: fragment("gen_random_uuid()"))
add(:concept, :string)
add(:mask, :string)
add(:answer, :string)

timestamps()
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Registrations.Repo.Migrations.AddWaydowntownGames do
use Ecto.Migration

def change do
create table(:games, prefix: "waydowntown", primary_key: false) do
add(:id, :uuid, primary_key: true, default: fragment("gen_random_uuid()"))
add(:incarnation_id, references("incarnations", type: :uuid))

timestamps()
end
end
end
94 changes: 91 additions & 3 deletions unmnemonic_devices_vrs/tests/fixtures/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 13.9
-- Dumped by pg_dump version 13.4
-- Dumped from database version 13.13
-- Dumped by pg_dump version 16.1

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand All @@ -23,13 +23,27 @@ SET row_security = off;
CREATE SCHEMA _sqlx_test;


--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

-- *not* creating schema, since initdb creates it


--
-- Name: unmnemonic_devices; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA unmnemonic_devices;


--
-- Name: waydowntown; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA waydowntown;


--
-- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: -
--
Expand Down Expand Up @@ -71,6 +85,18 @@ CREATE TABLE _sqlx_test.databases (
);


--
-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.ar_internal_metadata (
key character varying NOT NULL,
value character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);


--
-- Name: messages; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -267,6 +293,32 @@ CREATE SEQUENCE unmnemonic_devices.settings_id_seq
ALTER SEQUENCE unmnemonic_devices.settings_id_seq OWNED BY unmnemonic_devices.settings.id;


--
-- Name: games; Type: TABLE; Schema: waydowntown; Owner: -
--

CREATE TABLE waydowntown.games (
id uuid DEFAULT gen_random_uuid() NOT NULL,
incarnation_id uuid,
inserted_at timestamp(0) without time zone NOT NULL,
updated_at timestamp(0) without time zone NOT NULL
);


--
-- Name: incarnations; Type: TABLE; Schema: waydowntown; Owner: -
--

CREATE TABLE waydowntown.incarnations (
id uuid DEFAULT gen_random_uuid() NOT NULL,
concept character varying(255),
mask character varying(255),
answer character varying(255),
inserted_at timestamp(0) without time zone NOT NULL,
updated_at timestamp(0) without time zone NOT NULL
);


--
-- Name: settings id; Type: DEFAULT; Schema: unmnemonic_devices; Owner: -
--
Expand All @@ -282,6 +334,14 @@ ALTER TABLE ONLY _sqlx_test.databases
ADD CONSTRAINT databases_pkey PRIMARY KEY (db_name);


--
-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);


--
-- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -370,6 +430,22 @@ ALTER TABLE ONLY unmnemonic_devices.settings
ADD CONSTRAINT settings_pkey PRIMARY KEY (id);


--
-- Name: games games_pkey; Type: CONSTRAINT; Schema: waydowntown; Owner: -
--

ALTER TABLE ONLY waydowntown.games
ADD CONSTRAINT games_pkey PRIMARY KEY (id);


--
-- Name: incarnations incarnations_pkey; Type: CONSTRAINT; Schema: waydowntown; Owner: -
--

ALTER TABLE ONLY waydowntown.incarnations
ADD CONSTRAINT incarnations_pkey PRIMARY KEY (id);


--
-- Name: databases_created_at; Type: INDEX; Schema: _sqlx_test; Owner: -
--
Expand Down Expand Up @@ -424,7 +500,7 @@ CREATE UNIQUE INDEX recordings_team_id_index ON unmnemonic_devices.recordings US
--

ALTER TABLE ONLY public.users
ADD CONSTRAINT users_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id) ON DELETE CASCADE;
ADD CONSTRAINT users_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id) ON DELETE SET NULL;


--
Expand Down Expand Up @@ -507,6 +583,14 @@ ALTER TABLE ONLY unmnemonic_devices.recordings
ADD CONSTRAINT recordings_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id);


--
-- Name: games games_incarnation_id_fkey; Type: FK CONSTRAINT; Schema: waydowntown; Owner: -
--

ALTER TABLE ONLY waydowntown.games
ADD CONSTRAINT games_incarnation_id_fkey FOREIGN KEY (incarnation_id) REFERENCES waydowntown.incarnations(id);


--
-- PostgreSQL database dump complete
--
Expand Down Expand Up @@ -551,3 +635,7 @@ INSERT INTO public."schema_migrations" (version) VALUES (20231204001556);
INSERT INTO public."schema_migrations" (version) VALUES (20231205235352);
INSERT INTO public."schema_migrations" (version) VALUES (20231217183904);
INSERT INTO public."schema_migrations" (version) VALUES (20231220025457);
INSERT INTO public."schema_migrations" (version) VALUES (20240319155921);
INSERT INTO public."schema_migrations" (version) VALUES (20240630162659);
INSERT INTO public."schema_migrations" (version) VALUES (20240630162710);
INSERT INTO public."schema_migrations" (version) VALUES (20240630162715);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

class ApplicationRecord < ActiveRecord::Base
primary_abstract_class

class << self
private

def timestamp_attributes_for_create
super << 'inserted_at'
end
end
end
2 changes: 2 additions & 0 deletions waydowntown/waydowntown_server/app/models/game.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

class Game < ApplicationRecord
self.table_name = 'waydowntown.games'

belongs_to :incarnation
end
1 change: 1 addition & 0 deletions waydowntown/waydowntown_server/app/models/incarnation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

class Incarnation < ApplicationRecord
self.table_name = 'waydowntown.incarnations'
end
6 changes: 3 additions & 3 deletions waydowntown/waydowntown_server/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ default: &default

development:
<<: *default
database: waydowntown_development
database: registrations_dev

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: waydowntown_test
database: registrations_test

production:
<<: *default
database: waydowntown_production
database: registrations_prod

This file was deleted.

This file was deleted.

62 changes: 48 additions & 14 deletions waydowntown/waydowntown_server/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9976899

Please sign in to comment.