Commit 4a3891fd authored by okhin's avatar okhin 🚴

Merge branch '2-travailler-sur-l-import-des-donnees-dans-la-futur-base-de-donnees' into 'preprod'

Resolve "Travailler sur l'import des données dans la futur base de données"

Closes #2

See merge request !34
parents 9931f878 04d1fbf9
Pipeline #2149 failed with stages
in 1 minute and 15 seconds
......@@ -3,7 +3,7 @@
"description": "Site de soutien LQDN",
"require": {
"bcosca/fatfree": "^3.5",
"robmorgan/phinx": "^0.6.4",
"robmorgan/phinx": "^0.10.0",
"vlucas/phpdotenv": "^2.4",
"pimple/pimple": "^3.0",
"doctrine/dbal": "^2.5",
......
This diff is collapsed.
......@@ -28,7 +28,7 @@ class RemoveBonusTable extends AbstractMigration
public function change()
{
if ($this->hasTable('bonus')) {
$this->dropTable('bonus');
$this->table('bonus')->drop()->save();
}
}
}
<?php
use Phinx\Migration\AbstractMigration;
class UserEmailUnique extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('users');
$table->addIndex(['email'], ['unique' => true, 'name' => 'idx_users_emails'])
->update();
}
}
#!/bin/bash
# Cette monstruosité utilise un import/export par CSV de psql vers mariadb des utilisqteurs nécessaires. On pipe l'un dans l'autre. Il faut exécuter ce script avec des droits sudo.
PSQL_QUERY="COPY (SELECT DISTINCT ON (auth_user.email) email, auth_user.username pseudo FROM auth_user WHERE email NOT LIKE '' AND is_active = 't') TO STDOUT WITH (FORMAT CSV, HEADER, DELIMITER ',');"
MYSQL_QUERY="LOAD DATA LOCAL INFILE '/dev/stdin' INTO TABLE users FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\"' ESCAPED BY '\\"' LINES TERMINATED BY '\n' IGNORE 1 LINES (email, pseudo);"
sudo -u postgres psql -d soutien -c "$PSQL_QUERY" | mysql $SQL_DATABASE -u $SQL_USER -p$SQL_PASSWORD --local-infile=1 -e "$MYSQL_QUERY"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment