Merge pull request #9676 from colinux/fix-rails-schema

Tech: synchronize schema.rb
This commit is contained in:
Colin Darie 2023-11-20 13:25:21 +00:00 committed by GitHub
commit 7cb6eadf18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 307 additions and 231 deletions

View file

@ -0,0 +1,42 @@
name: Rails Schema Check
on:
push:
branches: [main]
paths:
- 'db/migrate/**'
- 'db/schema.rb'
pull_request:
branches: [main]
paths:
- 'db/migrate/**'
- 'db/schema.rb'
jobs:
check-migration-and-schema:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 2 # Fetch the last 2 commits to be able to compare with the base branch
- name: Check for migration and schema.rb changes
run: |
#!/bin/bash
set -e
latest_migration_file=$(ls -v db/migrate/*.rb | tail -n 1)
latest_migration_version=$(basename $latest_migration_file | grep -oE '^[0-9]+')
# Get the schema version, without underscores
schema_version=$(grep -oE 'define.version: [0-9_]+' db/schema.rb | cut -d ' ' -f 2 | tr -d _)
if [ "$latest_migration_version" != "$schema_version" ]; then
echo "schema.rb version does not match the latest migration version. Have you forgotten to update the schema.rb?"
echo " SCHEMA VERSION = $schema_version (config/schema.rb)"
echo " LATEST MIGRATION VERSION = $latest_migration_version ($latest_migration_file)"
exit 1
fi

View file

@ -1,4 +1,4 @@
class AddAncestryToGroupeGestionnaires < ActiveRecord::Migration[6.1] class AddAncestryToGroupeGestionnaires < ActiveRecord::Migration[7.0]
disable_ddl_transaction! disable_ddl_transaction!
def change def change

View file

@ -1,11 +1,17 @@
class AddInstructeurForeignKeyToExports < ActiveRecord::Migration[7.0] class AddInstructeurForeignKeyToExports < ActiveRecord::Migration[7.0]
disable_ddl_transaction! disable_ddl_transaction!
def change def up
# Foreign keys were already added on developer machines, but timeouted in production. # Foreign keys were already added on developer machines, but timeouted in production.
if !foreign_key_exists?(:exports, :instructeurs) if !foreign_key_exists?(:exports, :instructeurs)
add_foreign_key :exports, :instructeurs, validate: false add_foreign_key :exports, :instructeurs, validate: false
validate_foreign_key :exports, :instructeurs validate_foreign_key :exports, :instructeurs
end end
end end
def down
if foreign_key_exists?(:exports, :instructeurs)
remove_foreign_key :exports, :instructeurs
end
end
end end

View file

@ -0,0 +1,15 @@
class AddMissingExportsInstructeurIndex < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
if !index_exists?(:exports, :instructeur_id) # index may have already been added on other environments by a previous migration
add_index :exports, :instructeur_id, algorithm: :concurrently
end
end
def down
if index_exists?(:exports, :instructeur_id)
remove_index :exports, :instructeur_id
end
end
end

View file

@ -0,0 +1,15 @@
class AddMissingAdministrateursGroupeGestionnaireIndex < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
if !index_exists?(:administrateurs, :groupe_gestionnaire_id) # index may have already been added on other environments by a previous migration
add_index :administrateurs, :groupe_gestionnaire_id, algorithm: :concurrently
end
end
def down
if index_exists?(:administrateurs, :groupe_gestionnaire_id)
remove_index :administrateurs, :groupe_gestionnaire_id
end
end
end

File diff suppressed because it is too large Load diff

View file

@ -160,7 +160,7 @@ describe API::V2::GraphqlController do
context 'include Dossiers' do context 'include Dossiers' do
def cursor_for(item, column) def cursor_for(item, column)
cursor = [item.read_attribute(column).utc.strftime("%Y-%m-%dT%H:%M:%S.%NZ"), item.id].join(';') cursor = [item.reload.read_attribute(column).utc.strftime("%Y-%m-%dT%H:%M:%S.%NZ"), item.id].join(';')
API::V2::Schema.cursor_encoder.encode(cursor, nonce: true) API::V2::Schema.cursor_encoder.encode(cursor, nonce: true)
end end
@ -456,7 +456,7 @@ describe API::V2::GraphqlController do
context 'include deleted Dossiers' do context 'include deleted Dossiers' do
def cursor_for(item) def cursor_for(item)
cursor = [item.deleted_at.utc.strftime("%Y-%m-%dT%H:%M:%S.%NZ"), item.id].join(';') cursor = [item.reload.deleted_at.utc.strftime("%Y-%m-%dT%H:%M:%S.%NZ"), item.id].join(';')
API::V2::Schema.cursor_encoder.encode(cursor, nonce: true) API::V2::Schema.cursor_encoder.encode(cursor, nonce: true)
end end
@ -575,7 +575,7 @@ describe API::V2::GraphqlController do
context 'include pending deleted Dossiers' do context 'include pending deleted Dossiers' do
def cursor_for(item) def cursor_for(item)
cursor = [(item.en_construction? ? item.hidden_by_user_at : item.hidden_by_administration_at).utc.strftime("%Y-%m-%dT%H:%M:%S.%NZ"), item.id].join(';') cursor = [(item.reload.en_construction? ? item.hidden_by_user_at : item.hidden_by_administration_at).utc.strftime("%Y-%m-%dT%H:%M:%S.%NZ"), item.id].join(';')
API::V2::Schema.cursor_encoder.encode(cursor, nonce: true) API::V2::Schema.cursor_encoder.encode(cursor, nonce: true)
end end

View file

@ -173,6 +173,7 @@ RSpec.describe DossierCloneConcern do
context "as a fork" do context "as a fork" do
let(:new_dossier) { dossier.clone(fork: true) } let(:new_dossier) { dossier.clone(fork: true) }
before { dossier.champs_public.reload } # we compare timestamps so we have to get the precision limit from the db }
it { expect(new_dossier.editing_fork_origin).to eq(dossier) } it { expect(new_dossier.editing_fork_origin).to eq(dossier) }
it { expect(new_dossier.champs_public[0].id).not_to eq(dossier.champs_public[0].id) } it { expect(new_dossier.champs_public[0].id).not_to eq(dossier.champs_public[0].id) }
@ -181,7 +182,7 @@ RSpec.describe DossierCloneConcern do
context "piece justificative champ" do context "piece justificative champ" do
let(:champ_pj) { create(:champ_piece_justificative, dossier_id: dossier.id) } let(:champ_pj) { create(:champ_piece_justificative, dossier_id: dossier.id) }
before { dossier.champs_public << champ_pj } before { dossier.champs_public << champ_pj.reload }
it { it {
champ_pj_fork = Champs::PieceJustificativeChamp.where(dossier: new_dossier).first champ_pj_fork = Champs::PieceJustificativeChamp.where(dossier: new_dossier).first