Skip to content

Commit

Permalink
setting up migration to django
Browse files Browse the repository at this point in the history
requires fixing up table data for postgres and removing the entity linking from nines
  • Loading branch information
andrew-gardener committed Jun 20, 2024
1 parent 47478d5 commit 31f0a2f
Show file tree
Hide file tree
Showing 26 changed files with 485 additions and 33 deletions.
16 changes: 8 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.8'
services:
db:
container_name: bep_db
container_name: bep_db_old
image: mariadb:10.11
ports:
- "13306:3306"
Expand All @@ -22,13 +22,13 @@ services:
retries: 120

app:
container_name: bep_app
container_name: bep_app_old
# image: dhil/bep
build:
context: .
target: bep
ports:
- "8080:80"
- "8081:80"
volumes:
# code for development
- .:/var/www/html
Expand All @@ -52,8 +52,8 @@ services:
db:
condition: service_healthy

mail:
container_name: bep_mail
image: jcalonso/mailhog:v1.0.1
ports:
- "8025:8025"
# mail:
# container_name: bep_mail
# image: jcalonso/mailhog:v1.0.1
# ports:
# - "8025:8025"
87 changes: 87 additions & 0 deletions migrations/2024/06/Version20240619211029.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240619211029 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_36CE5E075E237E06 ON archdeaconry');
$this->addSql('ALTER TABLE archdeaconry ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('DROP INDEX UNIQ_D5FC5D9C5E237E06 ON archive');
$this->addSql('ALTER TABLE archive ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('ALTER TABLE book ADD links LONGTEXT DEFAULT NULL');
$this->addSql('DROP INDEX UNIQ_58E2FF255E237E06 ON county');
$this->addSql('ALTER TABLE county ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('DROP INDEX UNIQ_8849E7425E237E06 ON diocese');
$this->addSql('ALTER TABLE diocese ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('DROP INDEX UNIQ_DEBA72DF5E237E06 ON format');
$this->addSql('ALTER TABLE format DROP name');
$this->addSql('ALTER TABLE injunction ADD links LONGTEXT DEFAULT NULL');
$this->addSql('DROP INDEX UNIQ_CE3EE8025E237E06 ON manuscript_source');
$this->addSql('ALTER TABLE manuscript_source ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('DROP INDEX UNIQ_71FB7BAE5E237E06 ON monarch');
$this->addSql('ALTER TABLE monarch DROP name');
$this->addSql('DROP INDEX UNIQ_CC5A6D275E237E06 ON nation');
$this->addSql('ALTER TABLE nation DROP name');
$this->addSql('DROP INDEX UNIQ_DFF9A9785E237E06 ON parish');
$this->addSql('ALTER TABLE parish ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('ALTER TABLE print_source ADD links LONGTEXT DEFAULT NULL');
$this->addSql('DROP INDEX UNIQ_4ADAD40B5E237E06 ON province');
$this->addSql('ALTER TABLE province ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('DROP INDEX UNIQ_456C2F135E237E06 ON source_category');
$this->addSql('ALTER TABLE source_category DROP name');
$this->addSql('DROP INDEX UNIQ_4CE6C7A45E237E06 ON town');
$this->addSql('ALTER TABLE town ADD links LONGTEXT DEFAULT NULL, DROP name');
$this->addSql('DROP INDEX UNIQ_483E30A95E237E06 ON transaction_category');
$this->addSql('ALTER TABLE transaction_category DROP name');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE source_category ADD name VARCHAR(191) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_456C2F135E237E06 ON source_category (name)');
$this->addSql('ALTER TABLE format ADD name VARCHAR(191) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_DEBA72DF5E237E06 ON format (name)');
$this->addSql('ALTER TABLE archdeaconry ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_36CE5E075E237E06 ON archdeaconry (name)');
$this->addSql('ALTER TABLE transaction_category ADD name VARCHAR(191) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_483E30A95E237E06 ON transaction_category (name)');
$this->addSql('ALTER TABLE nation ADD name VARCHAR(191) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_CC5A6D275E237E06 ON nation (name)');
$this->addSql('ALTER TABLE injunction DROP links');
$this->addSql('ALTER TABLE parish ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_DFF9A9785E237E06 ON parish (name)');
$this->addSql('ALTER TABLE county ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_58E2FF255E237E06 ON county (name)');
$this->addSql('ALTER TABLE province ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_4ADAD40B5E237E06 ON province (name)');
$this->addSql('ALTER TABLE print_source DROP links');
$this->addSql('ALTER TABLE diocese ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8849E7425E237E06 ON diocese (name)');
$this->addSql('ALTER TABLE town ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_4CE6C7A45E237E06 ON town (name)');
$this->addSql('ALTER TABLE archive ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_D5FC5D9C5E237E06 ON archive (name)');
$this->addSql('ALTER TABLE monarch ADD name VARCHAR(191) NOT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_71FB7BAE5E237E06 ON monarch (name)');
$this->addSql('ALTER TABLE book DROP links');
$this->addSql('ALTER TABLE manuscript_source ADD name VARCHAR(191) NOT NULL, DROP links');
$this->addSql('CREATE UNIQUE INDEX UNIQ_CE3EE8025E237E06 ON manuscript_source (name)');
}
}
56 changes: 56 additions & 0 deletions migrations/2024/06/Version20240619211030.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240619211030 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$tables = [
['archdeaconry', 'Archdeaconry'],
['archive', 'Archive'],
['book', 'Book'],
['county', 'County'],
['diocese', 'Diocese'],
['injunction', 'Injunction'],
['manuscript_source', 'ManuscriptSource'],
['parish', 'Parish'],
['print_source', 'PrintSource'],
['province', 'Province'],
['town', 'Town'],
];
foreach ($tables as $table) {
$tableName = $table[0];
$entityName = $table[1];
$this->addSql("
UPDATE $tableName, (
SELECT $tableName.id, COALESCE(CONCAT('{', GROUP_CONCAT(nines_media_link.url ORDER BY nines_media_link.id SEPARATOR ','), '}'), '{}') AS links
FROM $tableName
LEFT JOIN nines_media_link ON nines_media_link.entity = CONCAT('App\\\\Entity\\\\$entityName:', $tableName.id)
GROUP BY nines_media_link.entity
) as links_query
SET $tableName.links = links_query.links
WHERE $tableName.id = links_query.id
");
}
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
44 changes: 44 additions & 0 deletions migrations/2024/06/Version20240619211031.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240619211031 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$tables = ['book', 'injunction'];
foreach ($tables as $tableName) {
$this->addSql("
UPDATE $tableName
SET variant_titles = REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(
variant_titles, '^a:[0-9]+:|i:[0-9]+;s:[0-9]+:', ''
),
'\";}', '\"}'
),
'\";\"', '\",\"'
)
");
}
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
42 changes: 42 additions & 0 deletions migrations/2024/06/Version20240619211032.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240619211032 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE nines_media_image DROP original_name');
$this->addSql('ALTER TABLE nines_media_image DROP file_size');
$this->addSql('ALTER TABLE nines_media_image DROP mime_type');
$this->addSql('ALTER TABLE nines_media_image DROP `checksum`');
$this->addSql('ALTER TABLE nines_media_image DROP source_url');
$this->addSql('ALTER TABLE nines_media_image CHANGE `path` `image` varchar(255)');
$this->addSql('ALTER TABLE nines_media_image CHANGE `thumb_path` `thumbnail` varchar(255)');

$this->addSql("
UPDATE nines_media_image
SET entity = REGEXP_REPLACE(entity, '^[a-zA-Z]+.[a-zA-Z]+.[a-zA-Z]+.', '')
");
$this->addSql('ALTER TABLE nines_media_image CHANGE `entity` `holding_id` int(11)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
55 changes: 55 additions & 0 deletions migrations/2024/06/Version20240619211033.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240619211033 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs

$this->addSql('RENAME TABLE archdeaconry to bep_archdeaconry');
$this->addSql('RENAME TABLE archive to bep_archive');
$this->addSql('RENAME TABLE book to bep_book');
$this->addSql('RENAME TABLE county to bep_county');
$this->addSql('RENAME TABLE diocese to bep_diocese');
$this->addSql('RENAME TABLE format to bep_format');
$this->addSql('RENAME TABLE holding to bep_holding');
$this->addSql('RENAME TABLE holding_book to bep_holding_books');
$this->addSql('RENAME TABLE nines_media_image to bep_holding_image');
$this->addSql('RENAME TABLE injunction to bep_injunction');
$this->addSql('RENAME TABLE inventory to bep_inventory');
$this->addSql('RENAME TABLE inventory_book to bep_inventory_books');
$this->addSql('RENAME TABLE manuscript_source to bep_manuscript_source');
$this->addSql('RENAME TABLE monarch to bep_monarch');
$this->addSql('RENAME TABLE nation to bep_nation');
$this->addSql('RENAME TABLE parish to bep_parish');
$this->addSql('RENAME TABLE print_source to bep_print_source');
$this->addSql('RENAME TABLE province to bep_province');
$this->addSql('RENAME TABLE source_category to bep_source_category');
$this->addSql('RENAME TABLE town to bep_town');
$this->addSql('RENAME TABLE transact to bep_transact');
$this->addSql('RENAME TABLE transaction_book to bep_transaction_books');
$this->addSql('RENAME TABLE transaction_category to bep_transaction_category');
$this->addSql('RENAME TABLE transaction_transaction_category to bep_transaction_transaction_categories');
// $this->addSql('RENAME TABLE nines_user to auth_user');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
49 changes: 49 additions & 0 deletions migrations/2024/06/Version20240619211034.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240619211034 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('UPDATE nines_user SET `password` = ""');
$this->addSql('ALTER TABLE nines_user CHANGE `login` `last_login` datetime');
$this->addSql('ALTER TABLE nines_user ADD is_superuser tinyint(1) DEFAULT False');
$this->addSql('UPDATE nines_user SET `is_superuser` = roles like \'%"ROLE_ADMIN"%\'');
$this->addSql('ALTER TABLE nines_user ADD username varchar(150) DEFAULT ""');
$this->addSql('UPDATE nines_user SET `username` = REGEXP_REPLACE(email, "\@.*$", "")');
$this->addSql('ALTER TABLE nines_user ADD first_name varchar(150) DEFAULT ""');
$this->addSql('ALTER TABLE nines_user ADD last_name varchar(150) DEFAULT ""');
$this->addSql('UPDATE nines_user SET `first_name` = REGEXP_REPLACE(fullname, " .*$", "")');
$this->addSql('UPDATE nines_user SET `last_name` = REGEXP_REPLACE(fullname, "^.* ", "")');
$this->addSql('ALTER TABLE nines_user ADD is_staff tinyint(1) DEFAULT True');
$this->addSql('ALTER TABLE nines_user CHANGE `active` `is_active` tinyint(1)');
$this->addSql('ALTER TABLE nines_user CHANGE `created` `date_joined` datetime');
$this->addSql('ALTER TABLE nines_user DROP reset_token');
$this->addSql('ALTER TABLE nines_user DROP reset_expiry');
$this->addSql('ALTER TABLE nines_user DROP fullname');
$this->addSql('ALTER TABLE nines_user DROP roles');
$this->addSql('ALTER TABLE nines_user DROP updated');
$this->addSql('ALTER TABLE nines_user DROP affiliation');
$this->addSql('RENAME TABLE nines_user to auth_user');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
Loading

0 comments on commit 31f0a2f

Please sign in to comment.