Skip to content

Commit

Permalink
Change waydowntown to share registrations database
Browse files Browse the repository at this point in the history
Seems rickety!
  • Loading branch information
backspace committed Jul 1, 2024
1 parent 3c2dda3 commit 2a84c71
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 79 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
90 changes: 56 additions & 34 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 @@ -17,10 +17,10 @@ SET client_min_messages = warning;
SET row_security = off;

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

CREATE SCHEMA _sqlx_test;
-- *not* creating schema, since initdb creates it


--
Expand All @@ -31,46 +31,30 @@ CREATE SCHEMA unmnemonic_devices;


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

CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
CREATE SCHEMA waydowntown;


--
-- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner: -
-- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: -
--

COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams';
CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;


--
-- Name: database_ids; Type: SEQUENCE; Schema: _sqlx_test; Owner: -
-- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner: -
--

CREATE SEQUENCE _sqlx_test.database_ids
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams';


SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: databases; Type: TABLE; Schema: _sqlx_test; Owner: -
--

CREATE TABLE _sqlx_test.databases (
db_name text NOT NULL,
test_path text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);


--
-- Name: messages; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -268,18 +252,36 @@ ALTER SEQUENCE unmnemonic_devices.settings_id_seq OWNED BY unmnemonic_devices.se


--
-- Name: settings id; Type: DEFAULT; Schema: unmnemonic_devices; Owner: -
-- Name: games; Type: TABLE; Schema: waydowntown; Owner: -
--

ALTER TABLE ONLY unmnemonic_devices.settings ALTER COLUMN id SET DEFAULT nextval('unmnemonic_devices.settings_id_seq'::regclass);
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: databases databases_pkey; Type: CONSTRAINT; Schema: _sqlx_test; Owner: -
-- Name: incarnations; Type: TABLE; Schema: waydowntown; Owner: -
--

ALTER TABLE ONLY _sqlx_test.databases
ADD CONSTRAINT databases_pkey PRIMARY KEY (db_name);
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: -
--

ALTER TABLE ONLY unmnemonic_devices.settings ALTER COLUMN id SET DEFAULT nextval('unmnemonic_devices.settings_id_seq'::regclass);


--
Expand Down Expand Up @@ -371,10 +373,19 @@ ALTER TABLE ONLY unmnemonic_devices.settings


--
-- Name: databases_created_at; Type: INDEX; Schema: _sqlx_test; Owner: -
-- Name: games games_pkey; Type: CONSTRAINT; Schema: waydowntown; Owner: -
--

CREATE INDEX databases_created_at ON _sqlx_test.databases USING btree (created_at);
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);


--
Expand Down Expand Up @@ -424,7 +435,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 +518,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 +570,6 @@ 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 (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
7 changes: 4 additions & 3 deletions waydowntown/waydowntown_server/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
default: &default
adapter: postgresql
schema_search_path: "waydowntown,public"
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

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.

72 changes: 60 additions & 12 deletions waydowntown/waydowntown_server/db/schema.rb

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

Loading

0 comments on commit 2a84c71

Please sign in to comment.