diff --git a/.github/workflows/ci-waydowntown-server.yml b/.github/workflows/ci-waydowntown-server.yml index 55b4f603..eb9610a4 100644 --- a/.github/workflows/ci-waydowntown-server.yml +++ b/.github/workflows/ci-waydowntown-server.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest services: postgres: - image: postgres:11-alpine + image: postgres:13-alpine ports: - "5432:5432" env: diff --git a/registrations/lib/dump-waydowntown-server-schema.sh b/registrations/lib/dump-waydowntown-server-schema.sh new file mode 100755 index 00000000..b8e57e09 --- /dev/null +++ b/registrations/lib/dump-waydowntown-server-schema.sh @@ -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" diff --git a/registrations/mix.exs b/registrations/mix.exs index 20513519..90ffc737 100644 --- a/registrations/mix.exs +++ b/registrations/mix.exs @@ -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"] ] diff --git a/registrations/priv/repo/migrations/20240630162659_add_waydowntown_schema.exs b/registrations/priv/repo/migrations/20240630162659_add_waydowntown_schema.exs new file mode 100644 index 00000000..034d9947 --- /dev/null +++ b/registrations/priv/repo/migrations/20240630162659_add_waydowntown_schema.exs @@ -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 diff --git a/registrations/priv/repo/migrations/20240630162710_add_waydowntown_incarnations.exs b/registrations/priv/repo/migrations/20240630162710_add_waydowntown_incarnations.exs new file mode 100644 index 00000000..c8ec87bc --- /dev/null +++ b/registrations/priv/repo/migrations/20240630162710_add_waydowntown_incarnations.exs @@ -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 diff --git a/registrations/priv/repo/migrations/20240630162715_add_waydowntown_games.exs b/registrations/priv/repo/migrations/20240630162715_add_waydowntown_games.exs new file mode 100644 index 00000000..6d17b504 --- /dev/null +++ b/registrations/priv/repo/migrations/20240630162715_add_waydowntown_games.exs @@ -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 diff --git a/unmnemonic_devices_vrs/tests/fixtures/schema.sql b/unmnemonic_devices_vrs/tests/fixtures/schema.sql index aaf46baf..cdce474a 100644 --- a/unmnemonic_devices_vrs/tests/fixtures/schema.sql +++ b/unmnemonic_devices_vrs/tests/fixtures/schema.sql @@ -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; @@ -23,6 +23,13 @@ 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: - -- @@ -30,6 +37,13 @@ CREATE SCHEMA _sqlx_test; CREATE SCHEMA unmnemonic_devices; +-- +-- Name: waydowntown; Type: SCHEMA; Schema: -; Owner: - +-- + +CREATE SCHEMA waydowntown; + + -- -- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: - -- @@ -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: - -- @@ -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: - -- @@ -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: - -- @@ -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: - -- @@ -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; -- @@ -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 -- @@ -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); diff --git a/waydowntown/waydowntown_server/app/models/application_record.rb b/waydowntown/waydowntown_server/app/models/application_record.rb index 08dc5379..352b6aa0 100644 --- a/waydowntown/waydowntown_server/app/models/application_record.rb +++ b/waydowntown/waydowntown_server/app/models/application_record.rb @@ -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 diff --git a/waydowntown/waydowntown_server/app/models/game.rb b/waydowntown/waydowntown_server/app/models/game.rb index 9a98a3a6..11aa03fb 100644 --- a/waydowntown/waydowntown_server/app/models/game.rb +++ b/waydowntown/waydowntown_server/app/models/game.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true class Game < ApplicationRecord + self.table_name = 'waydowntown.games' + belongs_to :incarnation end diff --git a/waydowntown/waydowntown_server/app/models/incarnation.rb b/waydowntown/waydowntown_server/app/models/incarnation.rb index 98df8973..f4c4ea39 100644 --- a/waydowntown/waydowntown_server/app/models/incarnation.rb +++ b/waydowntown/waydowntown_server/app/models/incarnation.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true class Incarnation < ApplicationRecord + self.table_name = 'waydowntown.incarnations' end diff --git a/waydowntown/waydowntown_server/config/database.yml b/waydowntown/waydowntown_server/config/database.yml index 213bb3a8..e1f835f4 100644 --- a/waydowntown/waydowntown_server/config/database.yml +++ b/waydowntown/waydowntown_server/config/database.yml @@ -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 diff --git a/waydowntown/waydowntown_server/db/migrate/20240622195313_create_incarnations.rb b/waydowntown/waydowntown_server/db/migrate/20240622195313_create_incarnations.rb deleted file mode 100644 index 3fce3246..00000000 --- a/waydowntown/waydowntown_server/db/migrate/20240622195313_create_incarnations.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -class CreateIncarnations < ActiveRecord::Migration[7.1] - def change - enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto') - - create_table :incarnations, id: :uuid, default: 'gen_random_uuid()' do |t| - t.string :concept - t.string :mask - t.string :answer - - t.timestamps - end - end -end diff --git a/waydowntown/waydowntown_server/db/migrate/20240628151327_create_games.rb b/waydowntown/waydowntown_server/db/migrate/20240628151327_create_games.rb deleted file mode 100644 index 4195eded..00000000 --- a/waydowntown/waydowntown_server/db/migrate/20240628151327_create_games.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class CreateGames < ActiveRecord::Migration[7.1] - def change - create_table :games, id: :uuid, default: 'gen_random_uuid()' do |t| - t.belongs_to :incarnation, type: :uuid, null: false, foreign_key: true - - t.timestamps - end - end -end diff --git a/waydowntown/waydowntown_server/db/schema.rb b/waydowntown/waydowntown_server/db/schema.rb index 16ca59b8..64ba862e 100644 --- a/waydowntown/waydowntown_server/db/schema.rb +++ b/waydowntown/waydowntown_server/db/schema.rb @@ -12,25 +12,59 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 20_240_628_151_327) do +ActiveRecord::Schema[7.1].define(version: 20_240_630_162_715) do + create_schema '_sqlx_test' + create_schema 'unmnemonic_devices' + create_schema 'waydowntown' + # These are extensions that must be enabled in order to support this database - enable_extension 'pgcrypto' + enable_extension 'pg_trgm' enable_extension 'plpgsql' - create_table 'games', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.uuid 'incarnation_id', null: false - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false - t.index ['incarnation_id'], name: 'index_games_on_incarnation_id' + create_table 'messages', id: :uuid, default: nil, force: :cascade do |t| + t.string 'subject', limit: 255 + t.text 'content' + t.boolean 'ready', default: false + t.date 'postmarked_at' + t.datetime 'inserted_at', precision: 0, null: false + t.datetime 'updated_at', precision: 0, null: false + t.text 'rendered_content' + t.boolean 'show_team' + t.string 'from_name', limit: 255 + t.string 'from_address', limit: 255 + end + + create_table 'teams', id: :uuid, default: nil, force: :cascade do |t| + t.text 'name' + t.integer 'risk_aversion' + t.text 'notes' + t.datetime 'inserted_at', precision: 0, null: false + t.datetime 'updated_at', precision: 0, null: false + t.string 'voicepass', limit: 255 + t.integer 'listens', default: 0 + t.virtual 'name_truncated', type: :string, limit: 53, + as: "\nCASE\n WHEN (length(name) > 50) THEN (\"substring\"(name, 1, (50 - \"position\"(reverse(\"substring\"(name, 1, 50)), ' '::text))) || '…'::text)\n ELSE name\nEND", stored: true end - create_table 'incarnations', id: :uuid, default: -> { 'gen_random_uuid()' }, force: :cascade do |t| - t.string 'concept' - t.string 'mask' - t.string 'answer' - t.datetime 'created_at', null: false - t.datetime 'updated_at', null: false + create_table 'users', id: :uuid, default: nil, force: :cascade do |t| + t.string 'email', limit: 255 + t.string 'crypted_password', limit: 255 + t.datetime 'inserted_at', precision: 0, null: false + t.datetime 'updated_at', precision: 0, null: false + t.boolean 'admin' + t.text 'team_emails' + t.text 'proposed_team_name' + t.integer 'risk_aversion' + t.text 'accessibility' + t.string 'recovery_hash', limit: 255 + t.text 'comments' + t.text 'source' + t.boolean 'attending' + t.string 'voicepass', limit: 255 + t.integer 'remembered', default: 0 + t.uuid 'team_id' + t.index ['email'], name: 'users_email_index', unique: true end - add_foreign_key 'games', 'incarnations' + add_foreign_key 'users', 'teams', name: 'users_team_id_fkey', on_delete: :nullify end