From: Andy Allan Date: Wed, 18 Oct 2023 15:25:27 +0000 (+0100) Subject: Merge pull request #4299 from AntonKhorev/no-changeset-action-button-css X-Git-Tag: live~1499 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/945df0f150ea803e1a654b03155ecdb444c6ed1c?hp=5e0792631ad5033af447ebb9427b3004c4e35a2c Merge pull request #4299 from AntonKhorev/no-changeset-action-button-css Remove subscribe/unsubscribe button custom css --- diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 685937b03..cdba19949 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -72,3 +72,27 @@ jobs: bundler-cache: true - name: Run brakeman run: bundle exec brakeman -q + annotate_models: + env: + RAILS_ENV: test + name: Rails Annotate Models + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ env.ruby }} + bundler-cache: true + - name: Setup database + run: | + sudo systemctl start postgresql + sudo -u postgres createuser -s $(id -un) + createdb openstreetmap + cp config/github.database.yml config/database.yml + bundle exec rails db:test:load + - name: Run Annotate Models + run: bundle exec rails annotate_models + - name: Fail if model annotations are out of date + run: git diff --exit-code diff --git a/Gemfile b/Gemfile index 724dd3bec..d8d49a1ce 100644 --- a/Gemfile +++ b/Gemfile @@ -136,7 +136,6 @@ gem "image_processing" # Gems useful for development group :development do - gem "annotate" gem "better_errors" gem "binding_of_caller" gem "debug_inspector" @@ -167,3 +166,7 @@ group :test do gem "simplecov-lcov", :require => false gem "webmock" end + +group :development, :test do + gem "annotate" +end diff --git a/app/models/changeset_comment.rb b/app/models/changeset_comment.rb index 1b78f98e8..3bc9483fa 100644 --- a/app/models/changeset_comment.rb +++ b/app/models/changeset_comment.rb @@ -11,7 +11,9 @@ # # Indexes # -# index_changeset_comments_on_created_at (created_at) +# index_changeset_comments_on_author_id_and_created_at (author_id,created_at) +# index_changeset_comments_on_changeset_id_and_created_at (changeset_id,created_at) +# index_changeset_comments_on_created_at (created_at) # # Foreign Keys # diff --git a/app/models/changeset_tag.rb b/app/models/changeset_tag.rb index 672e6f76c..cf8af6ba9 100644 --- a/app/models/changeset_tag.rb +++ b/app/models/changeset_tag.rb @@ -6,10 +6,6 @@ # k :string default(""), not null, primary key # v :string default(""), not null # -# Indexes -# -# changeset_tags_id_idx (changeset_id) -# # Foreign Keys # # changeset_tags_id_fkey (changeset_id => changesets.id) diff --git a/app/models/friendship.rb b/app/models/friendship.rb index 476821b47..2b1c7ce00 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -5,11 +5,12 @@ # id :bigint(8) not null, primary key # user_id :bigint(8) not null # friend_user_id :bigint(8) not null +# created_at :datetime # # Indexes # -# friends_user_id_idx (user_id) -# user_id_idx (friend_user_id) +# index_friends_on_user_id_and_created_at (user_id,created_at) +# user_id_idx (friend_user_id) # # Foreign Keys # diff --git a/app/models/note_comment.rb b/app/models/note_comment.rb index 635a5b0de..b870e5558 100644 --- a/app/models/note_comment.rb +++ b/app/models/note_comment.rb @@ -13,9 +13,10 @@ # # Indexes # -# index_note_comments_on_body (to_tsvector('english'::regconfig, body)) USING gin -# index_note_comments_on_created_at (created_at) -# note_comments_note_id_idx (note_id) +# index_note_comments_on_author_id_and_created_at (author_id,created_at) +# index_note_comments_on_body (to_tsvector('english'::regconfig, body)) USING gin +# index_note_comments_on_created_at (created_at) +# note_comments_note_id_idx (note_id) # # Foreign Keys # diff --git a/app/models/oauth2_application.rb b/app/models/oauth2_application.rb index 73a02417d..834f1ded5 100644 --- a/app/models/oauth2_application.rb +++ b/app/models/oauth2_application.rb @@ -1,3 +1,28 @@ +# == Schema Information +# +# Table name: oauth_applications +# +# id :bigint(8) not null, primary key +# owner_type :string not null +# owner_id :bigint(8) not null +# name :string not null +# uid :string not null +# secret :string not null +# redirect_uri :text not null +# scopes :string default(""), not null +# confidential :boolean default(TRUE), not null +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_oauth_applications_on_owner_type_and_owner_id (owner_type,owner_id) +# index_oauth_applications_on_uid (uid) UNIQUE +# +# Foreign Keys +# +# fk_rails_... (owner_id => users.id) +# class Oauth2Application < Doorkeeper::Application belongs_to :owner, :polymorphic => true diff --git a/app/models/oauth_nonce.rb b/app/models/oauth_nonce.rb index 86463f297..e08121cfc 100644 --- a/app/models/oauth_nonce.rb +++ b/app/models/oauth_nonce.rb @@ -2,7 +2,7 @@ # # Table name: oauth_nonces # -# id :bigint not null, primary key +# id :bigint(8) not null, primary key # nonce :string # timestamp :integer # created_at :datetime diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index c36d64572..6f122b260 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -2,7 +2,7 @@ # # Table name: relations # -# relation_id :bigint(8) default(0), not null, primary key +# relation_id :bigint(8) not null, primary key # changeset_id :bigint(8) not null # timestamp :datetime not null # version :bigint(8) not null, primary key diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index c99f60e7c..b556bd13f 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -2,7 +2,7 @@ # # Table name: relation_members # -# relation_id :bigint(8) default(0), not null, primary key +# relation_id :bigint(8) not null, primary key # member_type :enum not null # member_id :bigint(8) not null # member_role :string not null diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index c3a183891..2ed8f988d 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -2,7 +2,7 @@ # # Table name: relation_tags # -# relation_id :bigint(8) default(0), not null, primary key +# relation_id :bigint(8) not null, primary key # k :string default(""), not null, primary key # v :string default(""), not null # version :bigint(8) not null, primary key diff --git a/app/models/old_way.rb b/app/models/old_way.rb index fcff84ede..dabf0aafb 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -2,7 +2,7 @@ # # Table name: ways # -# way_id :bigint(8) default(0), not null, primary key +# way_id :bigint(8) not null, primary key # changeset_id :bigint(8) not null # timestamp :datetime not null # version :bigint(8) not null, primary key diff --git a/app/models/old_way_tag.rb b/app/models/old_way_tag.rb index 0342cf344..dd8968cb3 100644 --- a/app/models/old_way_tag.rb +++ b/app/models/old_way_tag.rb @@ -2,7 +2,7 @@ # # Table name: way_tags # -# way_id :bigint(8) default(0), not null, primary key +# way_id :bigint(8) not null, primary key # k :string not null, primary key # v :string not null # version :bigint(8) not null, primary key diff --git a/app/models/tracetag.rb b/app/models/tracetag.rb index 70296cd54..b1dde095c 100644 --- a/app/models/tracetag.rb +++ b/app/models/tracetag.rb @@ -2,7 +2,7 @@ # # Table name: gpx_file_tags # -# gpx_id :bigint(8) default(0), not null +# gpx_id :bigint(8) not null # tag :string not null # id :bigint(8) not null, primary key # diff --git a/app/models/user.rb b/app/models/user.rb index 3eb03a2fe..638928861 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,7 +12,6 @@ # home_lat :float # home_lon :float # home_zoom :integer default(3) -# nearby :integer default(50) # pass_salt :string # email_valid :boolean default(FALSE), not null # new_email :string diff --git a/config/initializers/migrate.rb b/config/initializers/migrate.rb index add6aaea9..0667e3346 100644 --- a/config/initializers/migrate.rb +++ b/config/initializers/migrate.rb @@ -1,31 +1,46 @@ if defined?(ActiveRecord::ConnectionAdapters::AbstractAdapter) module OpenStreetMap - module ActiveRecord - module PostgreSQLAdapter + module PostgreSQL + module Quoting def quote_column_name(name) Array(name).map { |n| super(n) }.join(", ") end + end - def add_primary_key(table_name, column_name, _options = {}) - table_name = quote_table_name(table_name) - column_name = quote_column_name(column_name) + module SchemaStatements + def add_primary_key(table_name, column_name, options = {}) + constraint_name = "#{table_name}_pkey" + + options = options.merge(:name => constraint_name, :unique => true) - execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{column_name})" + add_index(table_name, column_name, **options) + set_primary_key table_name, constraint_name end def remove_primary_key(table_name) + constraint_name = quote_table_name("#{table_name}_pkey") table_name = quote_table_name(table_name) - execute "ALTER TABLE #{table_name} DROP PRIMARY KEY" + execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint_name}" end - def alter_primary_key(table_name, new_columns) - constraint_name = quote_table_name("#{table_name}_pkey") + def alter_primary_key(table_name, column_name, options = {}) + constraint_name = "#{table_name}_pkey" + tmp_constraint_name = "#{table_name}_pkey_tmp" + + options = options.merge(:name => tmp_constraint_name, :unique => true) + + add_index(table_name, column_name, **options) + remove_primary_key table_name + set_primary_key table_name, tmp_constraint_name + rename_index table_name, tmp_constraint_name, constraint_name + end + + def set_primary_key(table_name, constraint_name) + constraint_name = quote_table_name(constraint_name) table_name = quote_table_name(table_name) - new_columns = quote_column_name(new_columns) - execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint_name}" - execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{new_columns})" + execute "ALTER TABLE #{table_name} ADD PRIMARY KEY USING INDEX #{constraint_name}" end def create_enumeration(enumeration_name, values) @@ -46,5 +61,6 @@ if defined?(ActiveRecord::ConnectionAdapters::AbstractAdapter) end end - ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(OpenStreetMap::ActiveRecord::PostgreSQLAdapter) + ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting.prepend(OpenStreetMap::PostgreSQL::Quoting) + ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements.prepend(OpenStreetMap::PostgreSQL::SchemaStatements) end diff --git a/db/migrate/20231007141103_add_primary_key_to_changeset_tags.rb b/db/migrate/20231007141103_add_primary_key_to_changeset_tags.rb new file mode 100644 index 000000000..6f0186576 --- /dev/null +++ b/db/migrate/20231007141103_add_primary_key_to_changeset_tags.rb @@ -0,0 +1,13 @@ +class AddPrimaryKeyToChangesetTags < ActiveRecord::Migration[7.0] + disable_ddl_transaction! + + def up + add_primary_key :changeset_tags, [:changeset_id, :k], :algorithm => :concurrently + remove_index :changeset_tags, [:changeset_id] + end + + def down + add_index :changeset_tags, [:changeset_id], :algorithm => :concurrently + remove_primary_key :changeset_tags + end +end diff --git a/db/structure.sql b/db/structure.sql index bd65755f2..939799c0a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1838,6 +1838,14 @@ ALTER TABLE ONLY public.changeset_comments ADD CONSTRAINT changeset_comments_pkey PRIMARY KEY (id); +-- +-- Name: changeset_tags changeset_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.changeset_tags + ADD CONSTRAINT changeset_tags_pkey PRIMARY KEY (changeset_id, k); + + -- -- Name: changesets changesets_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2205,13 +2213,6 @@ ALTER TABLE ONLY public.ways CREATE INDEX acls_k_idx ON public.acls USING btree (k); --- --- Name: changeset_tags_id_idx; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX changeset_tags_id_idx ON public.changeset_tags USING btree (changeset_id); - - -- -- Name: changesets_bbox_idx; Type: INDEX; Schema: public; Owner: - -- @@ -3466,6 +3467,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230825162137'), ('20230830115219'), ('20230830115220'), +('20231007141103'), ('21'), ('22'), ('23'), diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake index 70bc391a0..103e7fcc9 100644 --- a/lib/tasks/auto_annotate_models.rake +++ b/lib/tasks/auto_annotate_models.rake @@ -1,7 +1,7 @@ # NOTE: only doing this in development as some production environments (Heroku) # NOTE: are sensitive to local FS writes, and besides -- it's just not proper # NOTE: to have a dev-mode tool do its thing in production. -if Rails.env.development? +if Rails.env.development? || Rails.env.test? task :set_annotation_options => :environment do # You can override any of these by setting an environment variable of the # same name.