Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Don't add CREATE SCHEMA public commands to down migrations #551

Merged
merged 7 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ROLLBACK-PROCEDURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ From this point onwards, the Jenkins build triggers will push the build through

##### Step 2: From the command prompt of the Cloud 9 server `cd` into the `opg-digi-deps-api` directory and run `git pull origin master`.

##### Step 3: Using the integrated IDE, comment out any “CREATE SCHEMA public” commands in the `down()` method of any migration files that will be rolled back
An unresolved bug in Doctrine inadvertently adds this command in auto generated migrations.

##### Step 4: Run the PHP migration command from the command prompt, using the latest migration that you want to migrate to.
##### Step 3: Run the PHP migration command from the command prompt, using the latest migration that you want to migrate to.
For example, if migrations 103 and 102 need rolling back, we want run our migrations back to 101:

`php app/console doctrine:migrations:migrate 101 -n`
`php app/console doctrine:migrations:migrate 101 -n`

##### Step 5: Verify status of database and application.
##### Step 4: Verify status of database and application.



Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version182.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist_information DROP CONSTRAINT FK_3FB5A813B16D08A7');
$this->addSql('DROP TABLE checklist');
$this->addSql('DROP TABLE checklist_information');
Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version183.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist DROP CONSTRAINT FK_5C696D2F65CF370E');
$this->addSql('DROP INDEX IDX_5C696D2F65CF370E');
$this->addSql('ALTER TABLE checklist DROP last_modified_by');
Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version186.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist DROP satisfied_with_pa_expenses');
}
}
1 change: 0 additions & 1 deletion app/DoctrineMigrations/Version193.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist DROP satisfied_with_health_and_lifestyle');
}
}
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version196.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist RENAME COLUMN future_significant_decisions TO future_significant_financial_decisions');
}
}
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version198.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP TABLE prof_deputy_other_cost');
$this->addSql('CREATE INDEX created_on_idx ON report_submission (created_on)');

Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version201.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP TABLE prof_deputy_interim_cost');
}
}
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version204.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist DROP deputy_charge_allowed_by_court');
$this->addSql('ALTER TABLE casrec ADD registration_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
$this->addSql('ALTER TABLE casrec ADD last_logged_in TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
Expand Down
1 change: 0 additions & 1 deletion app/DoctrineMigrations/Version205.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE report DROP prof_dc_estimate_hc');
$this->addSql('DROP TABLE prof_deputy_estimate_cost');
}
Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version206.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE report DROP prof_dc_estimate_more_info');
$this->addSql('ALTER TABLE report DROP prof_dc_estimate_more_info_details');
}
Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version207.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist DROP payments_match_cost_certificate');
$this->addSql('ALTER TABLE checklist DROP prof_costs_reasonable_and_proportionate');
$this->addSql('ALTER TABLE checklist DROP has_deputy_overcharged_from_previous_estimates');
Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version208.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE report ADD prof_dc_hc_agreed BOOLEAN DEFAULT NULL');
}
}
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version210.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE checklist DROP next_billing_estimate_satisfactory');
}
}
1 change: 0 additions & 1 deletion app/DoctrineMigrations/Version211.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function down(Schema $schema)
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE report ADD prof_dc_hc_fixed BOOLEAN DEFAULT NULL');
$this->addSql('ALTER TABLE report ADD prof_dc_hc_assessed BOOLEAN DEFAULT NULL');
$this->addSql('ALTER TABLE report DROP prof_dc_how_charged');
Expand Down
2 changes: 0 additions & 2 deletions app/DoctrineMigrations/Version212.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE document ADD deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
}
}
15 changes: 1 addition & 14 deletions app/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
imports:
- { resource: services/assemblers.yml }
- { resource: services/controllers.yml }
- { resource: services/event_listeners.yml }
- { resource: services/rest_handlers.yml }
- { resource: services/repositories.yml }
- { resource: services/transformers.yml }

services:
kernel.listener.responseConverter:
class: AppBundle\EventListener\RestInputOuputFormatter
arguments: [ "@jms_serializer", "@logger", ["json"], "json", "%kernel.debug%" ]
public: true
tags:
- { name: kernel.event_listener, event: kernel.view, method: onKernelView }
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
em:
alias: doctrine.orm.entity_manager
public: true

doctrine.listener:
class: AppBundle\EventListener\DoctrineListener
tags:
- { name: doctrine.event_listener, event: prePersist, method: prePersist }
- { name: doctrine.event_listener, event: preRemove, method: preRemove }

opg_digideps.casrec_verification_service:
class: AppBundle\Service\CasrecVerificationService
arguments: [ "@em" ]
Expand Down
20 changes: 20 additions & 0 deletions app/config/services/event_listeners.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
kernel.listener.responseConverter:
class: AppBundle\EventListener\RestInputOuputFormatter
arguments: [ "@jms_serializer", "@logger", ["json"], "json", "%kernel.debug%" ]
public: true
tags:
- { name: kernel.event_listener, event: kernel.view, method: onKernelView }
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

doctrine.listener:
class: AppBundle\EventListener\DoctrineListener
tags:
- { name: doctrine.event_listener, event: prePersist, method: prePersist }
- { name: doctrine.event_listener, event: preRemove, method: preRemove }

AppBundle\EventListener\FixDefaultSchemaListener:
class: AppBundle\EventListener\FixDefaultSchemaListener
tags:
- { name: doctrine.event_listener, event: postGenerateSchema, method: postGenerateSchema }
2 changes: 1 addition & 1 deletion scripts/apiunittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export PGUSER=${API_DATABASE_USERNAME:=api}

cd /var/www
# clear cache
rm -rf var/*
rm -rf var/cache/*

rm -f /tmp/dd_stats.csv
rm -f /tmp/dd_stats.unittest.csv
Expand Down
23 changes: 23 additions & 0 deletions src/AppBundle/EventListener/FixDefaultSchemaListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace AppBundle\EventListener;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;

class FixDefaultSchemaListener implements EventSubscriber
{
public function getSubscribedEvents()
{
return ['postGenerateSchema'];
}

public function postGenerateSchema(GenerateSchemaEventArgs $args)
{
$schema = $args->getSchema();

if (!$schema->hasNamespace('public')) {
$schema->createNamespace('public');
}
}
}