Compare commits

...

14 Commits

Author SHA1 Message Date
Matthieu
26a7fe64be chore : update frontend submodule to master v1.0.0 2026-01-25 12:07:15 +01:00
Matthieu
4669dec359 chore : add versioning system and release script 2026-01-25 12:02:20 +01:00
Matthieu
3f05fe753e Update frontend submodule for piece requirements and component selections 2026-01-25 11:40:48 +01:00
Matthieu
a502acd234 Support multiple product requirements on pieces 2026-01-25 11:40:41 +01:00
Matthieu
69b199b6dc Update frontend submodule: overview machines + lighter PDF previews 2026-01-25 09:46:23 +01:00
Matthieu
d5f6749f9e wip: api filters and migration helpers 2026-01-23 23:30:05 +01:00
ad7918c993 chore(frontend) : met a jour le sous-module 2026-01-23 19:35:36 +01:00
86447000b1 feat(api) : ajoute pagination et filtres pour les catalogues 2026-01-23 19:35:26 +01:00
7da5eb917a feat(fixtures): ajouter système de fixtures pour les données
- fixtures/data.sql: dump des données actuelles de la base
- fixtures/load.sh: script shell de chargement
- makefile: targets fixtures-dump, fixtures-load, fixtures-reset

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 13:34:07 +01:00
d65eb9ff0f WIP: corrections sérialisation API et script normalisation SQL
Backend:
- Fix Groups sur TypeMachine*Requirement: exposer typePiece/typeComposant/typeProduct
- Fix Groups sur Document, Piece, Product, Composant pour sérialisation
- Add addConstructeur/removeConstructeur sur Piece et Product

Scripts:
- Fix normalize-dump.py: gérer les schémas quotés ("public"."table")

Frontend (sous-module):
- Corrections formulaires et sérialisation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 12:34:00 +01:00
895df7415b chore(frontend): maj sous-module 2026-01-15 13:43:33 +01:00
9abe9fea7f chore(migrations): normaliser le schema 2026-01-15 13:42:36 +01:00
ea45ce9d0a fix(schema): aligner mappings et sortie machine 2026-01-15 13:42:29 +01:00
2c3fbb093a feat(modeles): exposer la structure selon la categorie 2026-01-15 13:42:18 +01:00
37 changed files with 3351 additions and 182 deletions

138
RELEASE.md Normal file
View File

@@ -0,0 +1,138 @@
# Guide de Release
## Versioning
Le projet utilise le [Semantic Versioning](https://semver.org/) (SemVer) : `MAJOR.MINOR.PATCH`
- **MAJOR** : Changements incompatibles avec les versions précédentes
- **MINOR** : Nouvelles fonctionnalités rétrocompatibles
- **PATCH** : Corrections de bugs rétrocompatibles
La version est centralisée dans le fichier `VERSION` à la racine du projet.
## Créer une release
### Prérequis
- Tous les changements doivent être commités
- Les tests doivent passer
- Être sur la branche à releaser (ex: `main`, `develop`)
### Utilisation du script
```bash
# Afficher l'aide et la version actuelle
./scripts/release.sh
# Bump patch : 1.0.0 → 1.0.1
./scripts/release.sh patch
# Bump minor : 1.0.0 → 1.1.0
./scripts/release.sh minor
# Bump major : 1.0.0 → 2.0.0
./scripts/release.sh major
# Version spécifique
./scripts/release.sh 2.0.0
```
Le script :
1. Met à jour le fichier `VERSION`
2. Met à jour `config/packages/api_platform.yaml`
3. Crée un commit `chore(release): vX.Y.Z`
4. Crée le tag `vX.Y.Z`
### Pousser la release
```bash
git push && git push --tags
```
### Créer la release sur Gitea
1. Aller sur le dépôt Gitea
2. **Releases** > **New Release**
3. Sélectionner le tag `vX.Y.Z`
4. Titre : `v1.0.0` (ou avec un nom descriptif)
5. Description : résumé des changements (voir section Notes de release)
## Notes de release
Template pour les notes de release :
```markdown
## Nouveautés
- Feature A
- Feature B
## Corrections
- Fix du bug X
- Fix du bug Y
## Changements
- Refactoring de Z
- Mise à jour des dépendances
```
## Fichiers impactés par le versioning
| Fichier | Usage |
|---------|-------|
| `VERSION` | Source unique de vérité |
| `config/packages/api_platform.yaml` | Version affichée dans l'API |
| `Inventory_frontend/nuxt.config.ts` | Lit VERSION au build |
| Footer de l'app | Affiche `v{{ appVersion }}` |
## Déploiement en production
### 1. Base de données
Dump de la base locale :
```bash
pg_dump -h localhost -p 5433 -U root -d inventory > backup_v1.0.0.sql
```
Import en production :
```bash
psql -h <PROD_HOST> -U <PROD_USER> -d inventory < backup_v1.0.0.sql
```
### 2. Variables d'environnement production
Créer un fichier `.env.local` en production avec :
```env
APP_ENV=prod
APP_SECRET=<générer avec: openssl rand -hex 32>
DATABASE_URL="postgresql://user:password@host:5432/inventory?serverVersion=16"
CORS_ALLOW_ORIGIN='^https://votre-domaine\.com$'
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=<votre-passphrase>
```
### 3. Build production
Backend :
```bash
composer install --no-dev --optimize-autoloader
php bin/console cache:clear --env=prod
php bin/console doctrine:migrations:migrate --no-interaction
```
Frontend :
```bash
cd Inventory_frontend
NUXT_PUBLIC_API_BASE_URL=https://api.votre-domaine.com yarn build
```
### 4. Checklist avant mise en prod
- [ ] Tests passent
- [ ] Migrations DB testées
- [ ] Variables d'environnement configurées
- [ ] Clés JWT générées
- [ ] CORS configuré
- [ ] SSL/HTTPS actif
- [ ] Backup de la DB prod existante (si upgrade)

1
VERSION Normal file
View File

@@ -0,0 +1 @@
1.0.0

View File

@@ -1,6 +1,9 @@
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
mapping_types:
modelcategory: string
_text: string
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
@@ -9,7 +12,8 @@ doctrine:
profiling_collect_backtrace: '%kernel.debug%'
orm:
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
naming_strategy: doctrine.orm.naming_strategy.default
quote_strategy: doctrine.orm.quote_strategy.default
identity_generation_preferences:
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
auto_mapping: true

1042
fixtures/data.sql Normal file

File diff suppressed because one or more lines are too long

42
fixtures/load.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Load fixtures into the database
# Usage: ./fixtures/load.sh [--reset]
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Load environment variables
if [ -f "$PROJECT_DIR/.env" ]; then
export $(grep -v '^#' "$PROJECT_DIR/.env" | xargs)
fi
DB_USER="${POSTGRES_USER:-root}"
DB_NAME="${POSTGRES_DB:-inventory}"
CONTAINER="${DB_CONTAINER:-inventory-db-1}"
echo "Loading fixtures into $DB_NAME..."
# Check if --reset flag is passed
if [ "$1" == "--reset" ]; then
echo "Resetting database (truncating all tables)..."
docker exec -i "$CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" -c "
DO \$\$ DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename != 'doctrine_migration_versions') LOOP
EXECUTE 'TRUNCATE TABLE ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END \$\$;
"
fi
# Load fixtures with foreign key checks disabled
docker exec -i "$CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" <<EOF
SET session_replication_role = replica;
$(cat "$SCRIPT_DIR/data.sql")
SET session_replication_role = DEFAULT;
EOF
echo "Fixtures loaded successfully!"

View File

@@ -19,6 +19,8 @@ EXEC_PHP_ROOT = $(DOCKER) exec -t -u root $(PHP_CONTAINER)
EXEC_PHP_INTERACTIVE = $(DOCKER) exec -it -u $(APP_USER) $(PHP_CONTAINER)
EXEC_PHP_INTERACTIVE_ROOT = $(DOCKER) exec -it -u root $(PHP_CONTAINER)
FILES =
DATA_SQL ?= data.sql
DATA_SQL_NORM ?= data_norm.sql
#========================================================================================
@@ -58,7 +60,7 @@ build-nuxtJS:
$(EXEC_PHP) sh -lc "cd Inventory_frontend && npm install && npm run generate"
dev-nuxt:
$(EXEC_PHP) sh -c "cd Inventory_frontend && npm run dev"
$(EXEC_PHP) sh -lc "cd Inventory_frontend && npm run dev"
delete_built_dir:
CURRENT_UID=$(shell id -u) CURRENT_GID=$(shell id -g) $(DOCKER_COMPOSE) up -d
@@ -117,3 +119,31 @@ test:
wait:
sleep 10
# Normalize pgAdmin data-only dump and import into DB
import-data:
python3 scripts/normalize-dump.py $(DATA_SQL) $(DATA_SQL_NORM) --lower
$(DOCKER_COMPOSE) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -v ON_ERROR_STOP=1 -c "SET session_replication_role = replica;"
$(DOCKER_COMPOSE) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -v ON_ERROR_STOP=1 < $(DATA_SQL_NORM)
$(DOCKER_COMPOSE) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -v ON_ERROR_STOP=1 -c "SET session_replication_role = DEFAULT;"
# Fixtures management
fixtures-dump:
@echo "Dumping current database to fixtures/data.sql..."
$(DOCKER_COMPOSE) exec -T db pg_dump -U $(POSTGRES_USER) -d $(POSTGRES_DB) \
--data-only --inserts --no-owner --no-privileges \
--exclude-table=doctrine_migration_versions \
| grep -v "^pg_dump:" | grep -v "^\\\\restrict" > fixtures/data.sql
@echo "Fixtures saved to fixtures/data.sql"
fixtures-load:
@echo "Loading fixtures from fixtures/data.sql (FK checks disabled)..."
$(DOCKER_COMPOSE) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -c "SET session_replication_role = replica;"
-$(DOCKER_COMPOSE) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) < fixtures/data.sql
$(DOCKER_COMPOSE) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -c "SET session_replication_role = DEFAULT;"
@echo "Fixtures loaded!"
fixtures-reset:
@echo "Resetting database and loading fixtures..."
$(DOCKER_COMPOSE) exec -T db psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -c "DO \$$\$$ DECLARE r RECORD; BEGIN FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename != 'doctrine_migration_versions') LOOP EXECUTE 'TRUNCATE TABLE ' || quote_ident(r.tablename) || ' CASCADE'; END LOOP; END \$$\$$;"
$(MAKE) fixtures-load

35
migratebdd.md Normal file
View File

@@ -0,0 +1,35 @@
# Migration DB (manuel)
Ce guide explique comment importer un dump SQL venant de pgAdmin dans la base Docker.
## 1) Export pgAdmin
Dans pgAdmin:
- Format: Plain
- Options: Use INSERT commands + Use column inserts
- Fichier: `data.sql`
## 2) Normaliser le dump
Convertit les colonnes camelCase en lowercase compact.
```bash
python3 scripts/normalize-dump.py data.sql data_norm.sql --lower
```
## 3) Importer dans la base Docker
Utilise `session_replication_role` pour eviter les erreurs de contraintes circulaires.
```bash
docker compose --env-file docker/.env.docker.local exec -T db psql -U root -d inventory -v ON_ERROR_STOP=1 -c "SET session_replication_role = replica;"
docker compose --env-file docker/.env.docker.local exec -T db psql -U root -d inventory -v ON_ERROR_STOP=1 < data_norm.sql
docker compose --env-file docker/.env.docker.local exec -T db psql -U root -d inventory -v ON_ERROR_STOP=1 -c "SET session_replication_role = DEFAULT;"
```
## 4) Verifier
```bash
docker compose --env-file docker/.env.docker.local exec -T db psql -U $POSTGRES_USER -d $POSTGRES_DB -c "\\dt"
```

View File

@@ -0,0 +1,682 @@
<?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 Version20260120181438 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('CREATE TABLE IF NOT EXISTS model_types (id VARCHAR(36) NOT NULL, name VARCHAR(120) NOT NULL, code VARCHAR(60) NOT NULL, category VARCHAR(255) NOT NULL, notes TEXT DEFAULT NULL, description TEXT DEFAULT NULL, componentSkeleton JSON DEFAULT NULL, pieceSkeleton JSON DEFAULT NULL, productSkeleton JSON DEFAULT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updatedAt TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY (id))');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS UNIQ_6773A9C777153098 ON model_types (code)');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS unique_category_name ON model_types (category, name)');
$this->addSql('DROP TABLE IF EXISTS "ModelType"');
$this->addSql('DROP TABLE IF EXISTS _prisma_migrations');
$this->addSql('ALTER TABLE composants DROP CONSTRAINT IF EXISTS "composants_productId_fkey"');
$this->addSql('ALTER TABLE composants DROP CONSTRAINT IF EXISTS "composants_typeComposantId_fkey"');
$this->addSql('ALTER TABLE composants ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE composants ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE composants ALTER reference TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE composants ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE composants ALTER typeComposantId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE composants ALTER structure TYPE JSON');
$this->addSql('ALTER TABLE composants ALTER productId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE composants DROP CONSTRAINT IF EXISTS FK_F95A3199CC8A4CEE');
$this->addSql('ALTER TABLE composants ADD CONSTRAINT FK_F95A3199CC8A4CEE FOREIGN KEY (typeComposantId) REFERENCES model_types (id) NOT DEFERRABLE');
$this->addSql('ALTER TABLE composants DROP CONSTRAINT IF EXISTS FK_F95A319936799605');
$this->addSql('ALTER TABLE composants ADD CONSTRAINT FK_F95A319936799605 FOREIGN KEY (productId) REFERENCES products (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS composants_name_key RENAME TO UNIQ_F95A31995E237E06');
$this->addSql('ALTER INDEX IF EXISTS idx_f95a31999fd7f38f RENAME TO IDX_F95A3199CC8A4CEE');
$this->addSql('ALTER INDEX IF EXISTS idx_f95a319921c3ccfc RENAME TO IDX_F95A319936799605');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_ComposantConstructeurs_A_fkey"');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_ComposantConstructeurs_B_fkey"');
$this->addSql('DROP INDEX IF EXISTS "_ComposantConstructeurs_AB_unique"');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER A TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER B TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_60760125D3D99E8B');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_60760125D3D99E8B FOREIGN KEY (A) REFERENCES composants (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_607601254AD0CF31');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_607601254AD0CF31 FOREIGN KEY (B) REFERENCES constructeurs (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _ComposantConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _ComposantConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD PRIMARY KEY (A, B)');
$this->addSql('ALTER INDEX IF EXISTS idx_60760125f88a743c RENAME TO IDX_60760125D3D99E8B');
$this->addSql('ALTER INDEX IF EXISTS _composantconstructeurs_b_index RENAME TO IDX_607601254AD0CF31');
$this->addSql('ALTER TABLE constructeurs ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE constructeurs ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE constructeurs ALTER email TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE constructeurs ALTER phone TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE constructeurs ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER INDEX IF EXISTS constructeurs_name_key RENAME TO UNIQ_CC8D6F55E237E06');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS "custom_field_values_composantId_fkey"');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS "custom_field_values_customFieldId_fkey"');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS "custom_field_values_machineId_fkey"');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS "custom_field_values_pieceId_fkey"');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS "custom_field_values_productId_fkey"');
$this->addSql('ALTER TABLE custom_field_values ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_field_values ALTER value TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE custom_field_values ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE custom_field_values ALTER customFieldId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_field_values ALTER machineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_field_values ALTER composantId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_field_values ALTER pieceId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_field_values ALTER productId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF5C4A705F');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT FK_6B64D7FF5C4A705F FOREIGN KEY (customFieldId) REFERENCES custom_fields (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF633EC4FD');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT FK_6B64D7FF633EC4FD FOREIGN KEY (machineId) REFERENCES machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF345EE564');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT FK_6B64D7FF345EE564 FOREIGN KEY (composantId) REFERENCES composants (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF3C6A9D1');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT FK_6B64D7FF3C6A9D1 FOREIGN KEY (pieceId) REFERENCES pieces (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF36799605');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT FK_6B64D7FF36799605 FOREIGN KEY (productId) REFERENCES products (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ffdac15d53 RENAME TO IDX_6B64D7FF5C4A705F');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ff92f0f180 RENAME TO IDX_6B64D7FF633EC4FD');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ffea0a2b9e RENAME TO IDX_6B64D7FF345EE564');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ffd999eb60 RENAME TO IDX_6B64D7FF3C6A9D1');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ff21c3ccfc RENAME TO IDX_6B64D7FF36799605');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS "custom_fields_typeComposantId_fkey"');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS "custom_fields_typeMachineId_fkey"');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS "custom_fields_typePieceId_fkey"');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS "custom_fields_typeProductId_fkey"');
$this->addSql('ALTER TABLE custom_fields ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_fields ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE custom_fields ALTER type TYPE VARCHAR(50)');
$this->addSql('ALTER TABLE custom_fields ALTER defaultValue TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE custom_fields ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE custom_fields ALTER typeMachineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_fields ALTER typeComposantId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_fields ALTER typePieceId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_fields ALTER options TYPE JSON USING array_to_json(options)');
$this->addSql('ALTER TABLE custom_fields ALTER typeProductId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378C2F024C2');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT FK_4A48378C2F024C2 FOREIGN KEY (typeMachineId) REFERENCES type_machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378CCC8A4CEE');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT FK_4A48378CCC8A4CEE FOREIGN KEY (typeComposantId) REFERENCES model_types (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378C169F1CF6');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT FK_4A48378C169F1CF6 FOREIGN KEY (typePieceId) REFERENCES model_types (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378C57B7763A');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT FK_4A48378C57B7763A FOREIGN KEY (typeProductId) REFERENCES model_types (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378c542108fe RENAME TO IDX_4A48378C2F024C2');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378c9fd7f38f RENAME TO IDX_4A48378CCC8A4CEE');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378cf429180f RENAME TO IDX_4A48378C169F1CF6');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378ce7123582 RENAME TO IDX_4A48378C57B7763A');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS "documents_composantId_fkey"');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS "documents_machineId_fkey"');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS "documents_pieceId_fkey"');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS "documents_productId_fkey"');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS "documents_siteId_fkey"');
$this->addSql('ALTER TABLE documents ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE documents ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE documents ALTER filename TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE documents ALTER mimeType TYPE VARCHAR(100)');
$this->addSql('ALTER TABLE documents ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE documents ALTER machineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE documents ALTER composantId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE documents ALTER pieceId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE documents ALTER siteId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE documents ALTER productId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B07288633EC4FD');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT FK_A2B07288633EC4FD FOREIGN KEY (machineId) REFERENCES machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B07288345EE564');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT FK_A2B07288345EE564 FOREIGN KEY (composantId) REFERENCES composants (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B072883C6A9D1');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT FK_A2B072883C6A9D1 FOREIGN KEY (pieceId) REFERENCES pieces (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B0728836799605');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT FK_A2B0728836799605 FOREIGN KEY (productId) REFERENCES products (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B072886973A4FD');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT FK_A2B072886973A4FD FOREIGN KEY (siteId) REFERENCES sites (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b0728892f0f180 RENAME TO IDX_A2B07288633EC4FD');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b07288ea0a2b9e RENAME TO IDX_A2B07288345EE564');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b07288d999eb60 RENAME TO IDX_A2B072883C6A9D1');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b0728821c3ccfc RENAME TO IDX_A2B0728836799605');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b07288871a3650 RENAME TO IDX_A2B072886973A4FD');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS "machine_component_links_composantId_fkey"');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS "machine_component_links_machineId_fkey"');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS "machine_component_links_parentLinkId_fkey"');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS "machine_component_links_typeMachineComponentRequirementId_fkey"');
$this->addSql('ALTER TABLE machine_component_links ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_component_links ALTER machineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_component_links ALTER composantId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_component_links ALTER parentLinkId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_component_links ALTER typeMachineComponentRequirementId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_component_links ALTER nameOverride TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE machine_component_links ALTER referenceOverride TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE machine_component_links ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19633EC4FD');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT FK_528EFE19633EC4FD FOREIGN KEY (machineId) REFERENCES machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19345EE564');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT FK_528EFE19345EE564 FOREIGN KEY (composantId) REFERENCES composants (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19EF6CF34B');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT FK_528EFE19EF6CF34B FOREIGN KEY (parentLinkId) REFERENCES machine_component_links (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19C44B383C');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT FK_528EFE19C44B383C FOREIGN KEY (typeMachineComponentRequirementId) REFERENCES type_machine_component_requirements (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe1992f0f180 RENAME TO IDX_528EFE19633EC4FD');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe19ea0a2b9e RENAME TO IDX_528EFE19345EE564');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe191446d9b2 RENAME TO IDX_528EFE19EF6CF34B');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe19bbf9038c RENAME TO IDX_528EFE19C44B383C');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS "machine_piece_links_machineId_fkey"');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS "machine_piece_links_parentLinkId_fkey"');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS "machine_piece_links_pieceId_fkey"');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS "machine_piece_links_typeMachinePieceRequirementId_fkey"');
$this->addSql('ALTER TABLE machine_piece_links ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_piece_links ALTER machineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_piece_links ALTER pieceId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_piece_links ALTER parentLinkId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_piece_links ALTER typeMachinePieceRequirementId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_piece_links ALTER nameOverride TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE machine_piece_links ALTER referenceOverride TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE machine_piece_links ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_62941615633EC4FD');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT FK_62941615633EC4FD FOREIGN KEY (machineId) REFERENCES machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_629416153C6A9D1');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT FK_629416153C6A9D1 FOREIGN KEY (pieceId) REFERENCES pieces (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_62941615EF6CF34B');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT FK_62941615EF6CF34B FOREIGN KEY (parentLinkId) REFERENCES machine_component_links (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_62941615F957D314');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT FK_62941615F957D314 FOREIGN KEY (typeMachinePieceRequirementId) REFERENCES type_machine_piece_requirements (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_6294161592f0f180 RENAME TO IDX_62941615633EC4FD');
$this->addSql('ALTER INDEX IF EXISTS idx_62941615d999eb60 RENAME TO IDX_629416153C6A9D1');
$this->addSql('ALTER INDEX IF EXISTS idx_629416151446d9b2 RENAME TO IDX_62941615EF6CF34B');
$this->addSql('ALTER INDEX IF EXISTS idx_629416156e0f7201 RENAME TO IDX_62941615F957D314');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS "machine_product_links_machineId_fkey"');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS "machine_product_links_parentComponentLinkId_fkey"');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS "machine_product_links_parentLinkId_fkey"');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS "machine_product_links_parentPieceLinkId_fkey"');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS "machine_product_links_productId_fkey"');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS "machine_product_links_typeMachineProductRequirementId_fkey"');
$this->addSql('ALTER TABLE machine_product_links ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_product_links ALTER machineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_product_links ALTER productId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_product_links ALTER typeMachineProductRequirementId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_product_links ALTER parentLinkId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_product_links ALTER parentComponentLinkId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_product_links ALTER parentPieceLinkId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machine_product_links ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259633EC4FD');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT FK_8CC32259633EC4FD FOREIGN KEY (machineId) REFERENCES machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC3225936799605');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT FK_8CC3225936799605 FOREIGN KEY (productId) REFERENCES products (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259B590B209');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT FK_8CC32259B590B209 FOREIGN KEY (typeMachineProductRequirementId) REFERENCES type_machine_product_requirements (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259EF6CF34B');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT FK_8CC32259EF6CF34B FOREIGN KEY (parentLinkId) REFERENCES machine_product_links (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259A63AC5DC');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT FK_8CC32259A63AC5DC FOREIGN KEY (parentComponentLinkId) REFERENCES machine_component_links (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259937A1D7C');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT FK_8CC32259937A1D7C FOREIGN KEY (parentPieceLinkId) REFERENCES machine_piece_links (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS machine_product_links_machineid_idx RENAME TO IDX_8CC32259633EC4FD');
$this->addSql('ALTER INDEX IF EXISTS machine_product_links_productid_idx RENAME TO IDX_8CC3225936799605');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259187fc99c RENAME TO IDX_8CC32259B590B209');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc322591446d9b2 RENAME TO IDX_8CC32259EF6CF34B');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259bd5b4086 RENAME TO IDX_8CC32259A63AC5DC');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259b1619fa4 RENAME TO IDX_8CC32259937A1D7C');
$this->addSql('ALTER TABLE machines DROP CONSTRAINT IF EXISTS "machines_siteId_fkey"');
$this->addSql('ALTER TABLE machines DROP CONSTRAINT IF EXISTS "machines_typeMachineId_fkey"');
$this->addSql('ALTER TABLE machines ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machines ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE machines ALTER reference TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE machines ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE machines ALTER siteId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machines ALTER typeMachineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE machines DROP CONSTRAINT IF EXISTS FK_F1CE8DED6973A4FD');
$this->addSql('ALTER TABLE machines ADD CONSTRAINT FK_F1CE8DED6973A4FD FOREIGN KEY (siteId) REFERENCES sites (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE machines DROP CONSTRAINT IF EXISTS FK_F1CE8DED2F024C2');
$this->addSql('ALTER TABLE machines ADD CONSTRAINT FK_F1CE8DED2F024C2 FOREIGN KEY (typeMachineId) REFERENCES type_machines (id) NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS machines_name_key RENAME TO UNIQ_F1CE8DED5E237E06');
$this->addSql('ALTER INDEX IF EXISTS idx_f1ce8ded871a3650 RENAME TO IDX_F1CE8DED6973A4FD');
$this->addSql('ALTER INDEX IF EXISTS idx_f1ce8ded542108fe RENAME TO IDX_F1CE8DED2F024C2');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_MachineConstructeurs_A_fkey"');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_MachineConstructeurs_B_fkey"');
$this->addSql('DROP INDEX IF EXISTS "_MachineConstructeurs_AB_unique"');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER A TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER B TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_E6A040CCD3D99E8B');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_E6A040CCD3D99E8B FOREIGN KEY (A) REFERENCES machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_E6A040CC4AD0CF31');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_E6A040CC4AD0CF31 FOREIGN KEY (B) REFERENCES constructeurs (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _MachineConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _MachineConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD PRIMARY KEY (A, B)');
$this->addSql('ALTER INDEX IF EXISTS idx_e6a040ccf88a743c RENAME TO IDX_E6A040CCD3D99E8B');
$this->addSql('ALTER INDEX IF EXISTS _machineconstructeurs_b_index RENAME TO IDX_E6A040CC4AD0CF31');
$this->addSql('ALTER TABLE pieces DROP CONSTRAINT IF EXISTS "pieces_productId_fkey"');
$this->addSql('ALTER TABLE pieces DROP CONSTRAINT IF EXISTS "pieces_typePieceId_fkey"');
$this->addSql('ALTER TABLE pieces ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE pieces ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE pieces ALTER reference TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE pieces ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE pieces ALTER typePieceId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE pieces ALTER productId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE pieces DROP CONSTRAINT IF EXISTS FK_B92D7472169F1CF6');
$this->addSql('ALTER TABLE pieces ADD CONSTRAINT FK_B92D7472169F1CF6 FOREIGN KEY (typePieceId) REFERENCES model_types (id) NOT DEFERRABLE');
$this->addSql('ALTER TABLE pieces DROP CONSTRAINT IF EXISTS FK_B92D747236799605');
$this->addSql('ALTER TABLE pieces ADD CONSTRAINT FK_B92D747236799605 FOREIGN KEY (productId) REFERENCES products (id) ON DELETE SET NULL NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS pieces_name_key RENAME TO UNIQ_B92D74725E237E06');
$this->addSql('ALTER INDEX IF EXISTS idx_b92d7472f429180f RENAME TO IDX_B92D7472169F1CF6');
$this->addSql('ALTER INDEX IF EXISTS idx_b92d747221c3ccfc RENAME TO IDX_B92D747236799605');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_PieceConstructeurs_A_fkey"');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_PieceConstructeurs_B_fkey"');
$this->addSql('DROP INDEX IF EXISTS "_PieceConstructeurs_AB_unique"');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER A TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER B TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_E94732E5D3D99E8B');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_E94732E5D3D99E8B FOREIGN KEY (A) REFERENCES pieces (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_E94732E54AD0CF31');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_E94732E54AD0CF31 FOREIGN KEY (B) REFERENCES constructeurs (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _PieceConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _PieceConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD PRIMARY KEY (A, B)');
$this->addSql('ALTER INDEX IF EXISTS idx_e94732e5f88a743c RENAME TO IDX_E94732E5D3D99E8B');
$this->addSql('ALTER INDEX IF EXISTS _piececonstructeurs_b_index RENAME TO IDX_E94732E54AD0CF31');
$this->addSql('ALTER TABLE products DROP CONSTRAINT IF EXISTS "products_typeProductId_fkey"');
$this->addSql('ALTER TABLE products ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE products ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE products ALTER reference TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE products ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE products ALTER typeProductId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE products DROP CONSTRAINT IF EXISTS FK_B3BA5A5A57B7763A');
$this->addSql('ALTER TABLE products ADD CONSTRAINT FK_B3BA5A5A57B7763A FOREIGN KEY (typeProductId) REFERENCES model_types (id) NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS products_name_key RENAME TO UNIQ_B3BA5A5A5E237E06');
$this->addSql('ALTER INDEX IF EXISTS idx_b3ba5a5ae7123582 RENAME TO IDX_B3BA5A5A57B7763A');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_ProductConstructeurs_A_fkey"');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS "_ProductConstructeurs_B_fkey"');
$this->addSql('DROP INDEX IF EXISTS "_ProductConstructeurs_AB_unique"');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER A TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" ALTER B TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_CF7403FCD3D99E8B');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_CF7403FCD3D99E8B FOREIGN KEY (A) REFERENCES products (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS FK_CF7403FC4AD0CF31');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD CONSTRAINT FK_CF7403FC4AD0CF31 FOREIGN KEY (B) REFERENCES constructeurs (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _ProductConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" DROP CONSTRAINT IF EXISTS _ProductConstructeurs_pkey');
$this->addSql('ALTER TABLE IF EXISTS "$1" ADD PRIMARY KEY (A, B)');
$this->addSql('ALTER INDEX IF EXISTS idx_cf7403fcf88a743c RENAME TO IDX_CF7403FCD3D99E8B');
$this->addSql('ALTER INDEX IF EXISTS _productconstructeurs_b_index RENAME TO IDX_CF7403FC4AD0CF31');
$this->addSql('ALTER TABLE profiles ADD COLUMN IF NOT EXISTS email VARCHAR(180) DEFAULT NULL');
$this->addSql('ALTER TABLE profiles ADD COLUMN IF NOT EXISTS roles JSON DEFAULT \'["ROLE_USER"]\' NOT NULL');
$this->addSql('ALTER TABLE profiles ADD COLUMN IF NOT EXISTS password VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE profiles ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE profiles ALTER firstname TYPE VARCHAR(100)');
$this->addSql('ALTER TABLE profiles ALTER lastname TYPE VARCHAR(100)');
$this->addSql('ALTER TABLE profiles ALTER createdat DROP DEFAULT');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS UNIQ_email ON profiles (email)');
$this->addSql('ALTER TABLE sites ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE sites ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE sites ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE sites ALTER contactName TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE sites ALTER contactPhone TYPE VARCHAR(20)');
$this->addSql('ALTER TABLE sites ALTER contactAddress TYPE VARCHAR(500)');
$this->addSql('ALTER TABLE sites ALTER contactPostalCode TYPE VARCHAR(10)');
$this->addSql('ALTER TABLE sites ALTER contactCity TYPE VARCHAR(100)');
$this->addSql('ALTER TABLE type_machine_component_requirements DROP CONSTRAINT IF EXISTS "type_machine_component_requirements_typeComposantId_fkey"');
$this->addSql('ALTER TABLE type_machine_component_requirements DROP CONSTRAINT IF EXISTS "type_machine_component_requirements_typeMachineId_fkey"');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER label TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER typeMachineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER typeComposantId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_component_requirements DROP CONSTRAINT IF EXISTS FK_969587902F024C2');
$this->addSql('ALTER TABLE type_machine_component_requirements ADD CONSTRAINT FK_969587902F024C2 FOREIGN KEY (typeMachineId) REFERENCES type_machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE type_machine_component_requirements DROP CONSTRAINT IF EXISTS FK_96958790CC8A4CEE');
$this->addSql('ALTER TABLE type_machine_component_requirements ADD CONSTRAINT FK_96958790CC8A4CEE FOREIGN KEY (typeComposantId) REFERENCES model_types (id) NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_96958790542108fe RENAME TO IDX_969587902F024C2');
$this->addSql('ALTER INDEX IF EXISTS idx_969587909fd7f38f RENAME TO IDX_96958790CC8A4CEE');
$this->addSql('ALTER TABLE type_machine_piece_requirements DROP CONSTRAINT IF EXISTS "type_machine_piece_requirements_typeMachineId_fkey"');
$this->addSql('ALTER TABLE type_machine_piece_requirements DROP CONSTRAINT IF EXISTS "type_machine_piece_requirements_typePieceId_fkey"');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER label TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER typeMachineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER typePieceId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_piece_requirements DROP CONSTRAINT IF EXISTS FK_F609E59E2F024C2');
$this->addSql('ALTER TABLE type_machine_piece_requirements ADD CONSTRAINT FK_F609E59E2F024C2 FOREIGN KEY (typeMachineId) REFERENCES type_machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE type_machine_piece_requirements DROP CONSTRAINT IF EXISTS FK_F609E59E169F1CF6');
$this->addSql('ALTER TABLE type_machine_piece_requirements ADD CONSTRAINT FK_F609E59E169F1CF6 FOREIGN KEY (typePieceId) REFERENCES model_types (id) NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_f609e59e542108fe RENAME TO IDX_F609E59E2F024C2');
$this->addSql('ALTER INDEX IF EXISTS idx_f609e59ef429180f RENAME TO IDX_F609E59E169F1CF6');
$this->addSql('ALTER TABLE type_machine_product_requirements DROP CONSTRAINT IF EXISTS "type_machine_product_requirements_typeMachineId_fkey"');
$this->addSql('ALTER TABLE type_machine_product_requirements DROP CONSTRAINT IF EXISTS "type_machine_product_requirements_typeProductId_fkey"');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER label TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER typeMachineId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER typeProductId TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machine_product_requirements DROP CONSTRAINT IF EXISTS FK_29A51F982F024C2');
$this->addSql('ALTER TABLE type_machine_product_requirements ADD CONSTRAINT FK_29A51F982F024C2 FOREIGN KEY (typeMachineId) REFERENCES type_machines (id) ON DELETE CASCADE NOT DEFERRABLE');
$this->addSql('ALTER TABLE type_machine_product_requirements DROP CONSTRAINT IF EXISTS FK_29A51F9857B7763A');
$this->addSql('ALTER TABLE type_machine_product_requirements ADD CONSTRAINT FK_29A51F9857B7763A FOREIGN KEY (typeProductId) REFERENCES model_types (id) NOT DEFERRABLE');
$this->addSql('ALTER INDEX IF EXISTS idx_29a51f98542108fe RENAME TO IDX_29A51F982F024C2');
$this->addSql('ALTER INDEX IF EXISTS idx_29a51f98e7123582 RENAME TO IDX_29A51F9857B7763A');
$this->addSql('ALTER TABLE type_machines ADD COLUMN IF NOT EXISTS category VARCHAR(255)');
$this->addSql('ALTER TABLE type_machines ADD COLUMN IF NOT EXISTS maintenanceFrequency VARCHAR(255)');
$this->addSql('ALTER TABLE type_machines ADD COLUMN IF NOT EXISTS components JSON');
$this->addSql('ALTER TABLE type_machines ADD COLUMN IF NOT EXISTS criticalParts JSON');
$this->addSql('ALTER TABLE type_machines ADD COLUMN IF NOT EXISTS specifications JSON');
$this->addSql('ALTER TABLE type_machines ADD COLUMN IF NOT EXISTS machinePieces JSON');
$this->addSql('ALTER TABLE type_machines ALTER id TYPE VARCHAR(36)');
$this->addSql('ALTER TABLE type_machines ALTER name TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE type_machines ALTER category TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE type_machines ALTER maintenanceFrequency TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE type_machines ALTER components TYPE JSON');
$this->addSql('ALTER TABLE type_machines ALTER criticalParts TYPE JSON');
$this->addSql('ALTER TABLE type_machines ALTER specifications TYPE JSON');
$this->addSql('ALTER TABLE type_machines ALTER createdAt DROP DEFAULT');
$this->addSql('ALTER TABLE type_machines ALTER machinePieces TYPE JSON');
$this->addSql('ALTER INDEX IF EXISTS type_machines_name_key RENAME TO UNIQ_3C31AA115E237E06');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE "ModelType" (id TEXT NOT NULL, name VARCHAR(120) NOT NULL, code VARCHAR(60) NOT NULL, category VARCHAR NOT NULL, notes TEXT DEFAULT NULL, "createdAt" TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, "updatedAt" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, description TEXT DEFAULT NULL, "componentSkeleton" JSONB DEFAULT NULL, "pieceSkeleton" JSONB DEFAULT NULL, "productSkeleton" JSONB DEFAULT NULL, PRIMARY KEY (id))');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS "ModelType_code_key" ON "ModelType" (code)');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS "ModelType_category_name_key" ON "ModelType" (category, name)');
$this->addSql('CREATE TABLE _prisma_migrations (id VARCHAR(36) NOT NULL, checksum VARCHAR(64) NOT NULL, finished_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, migration_name VARCHAR(255) NOT NULL, logs TEXT DEFAULT NULL, rolled_back_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL, started_at TIMESTAMP(0) WITH TIME ZONE DEFAULT \'now()\' NOT NULL, applied_steps_count INT DEFAULT 0 NOT NULL, PRIMARY KEY (id))');
$this->addSql('DROP TABLE model_types');
$this->addSql('ALTER TABLE _ComposantConstructeurs DROP CONSTRAINT IF EXISTS FK_60760125D3D99E8B');
$this->addSql('ALTER TABLE _ComposantConstructeurs DROP CONSTRAINT IF EXISTS FK_607601254AD0CF31');
$this->addSql('ALTER TABLE _ComposantConstructeurs DROP CONSTRAINT IF EXISTS _ComposantConstructeurs_pkey');
$this->addSql('ALTER TABLE _ComposantConstructeurs ALTER "A" TYPE TEXT');
$this->addSql('ALTER TABLE _ComposantConstructeurs ALTER "B" TYPE TEXT');
$this->addSql('ALTER TABLE _ComposantConstructeurs ADD CONSTRAINT "_ComposantConstructeurs_A_fkey" FOREIGN KEY ("A") REFERENCES composants (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE _ComposantConstructeurs ADD CONSTRAINT "_ComposantConstructeurs_B_fkey" FOREIGN KEY ("B") REFERENCES constructeurs (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS "_ComposantConstructeurs_AB_unique" ON _ComposantConstructeurs ("A", "B")');
$this->addSql('ALTER INDEX IF EXISTS idx_607601254ad0cf31 RENAME TO "_ComposantConstructeurs_B_index"');
$this->addSql('ALTER INDEX IF EXISTS idx_60760125d3d99e8b RENAME TO IDX_60760125F88A743C');
$this->addSql('ALTER TABLE _MachineConstructeurs DROP CONSTRAINT IF EXISTS FK_E6A040CCD3D99E8B');
$this->addSql('ALTER TABLE _MachineConstructeurs DROP CONSTRAINT IF EXISTS FK_E6A040CC4AD0CF31');
$this->addSql('ALTER TABLE _MachineConstructeurs DROP CONSTRAINT IF EXISTS _MachineConstructeurs_pkey');
$this->addSql('ALTER TABLE _MachineConstructeurs ALTER "A" TYPE TEXT');
$this->addSql('ALTER TABLE _MachineConstructeurs ALTER "B" TYPE TEXT');
$this->addSql('ALTER TABLE _MachineConstructeurs ADD CONSTRAINT "_MachineConstructeurs_A_fkey" FOREIGN KEY ("A") REFERENCES machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE _MachineConstructeurs ADD CONSTRAINT "_MachineConstructeurs_B_fkey" FOREIGN KEY ("B") REFERENCES constructeurs (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS "_MachineConstructeurs_AB_unique" ON _MachineConstructeurs ("A", "B")');
$this->addSql('ALTER INDEX IF EXISTS idx_e6a040cc4ad0cf31 RENAME TO "_MachineConstructeurs_B_index"');
$this->addSql('ALTER INDEX IF EXISTS idx_e6a040ccd3d99e8b RENAME TO IDX_E6A040CCF88A743C');
$this->addSql('ALTER TABLE _PieceConstructeurs DROP CONSTRAINT IF EXISTS FK_E94732E5D3D99E8B');
$this->addSql('ALTER TABLE _PieceConstructeurs DROP CONSTRAINT IF EXISTS FK_E94732E54AD0CF31');
$this->addSql('ALTER TABLE _PieceConstructeurs DROP CONSTRAINT IF EXISTS _PieceConstructeurs_pkey');
$this->addSql('ALTER TABLE _PieceConstructeurs ALTER "A" TYPE TEXT');
$this->addSql('ALTER TABLE _PieceConstructeurs ALTER "B" TYPE TEXT');
$this->addSql('ALTER TABLE _PieceConstructeurs ADD CONSTRAINT "_PieceConstructeurs_A_fkey" FOREIGN KEY ("A") REFERENCES pieces (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE _PieceConstructeurs ADD CONSTRAINT "_PieceConstructeurs_B_fkey" FOREIGN KEY ("B") REFERENCES constructeurs (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS "_PieceConstructeurs_AB_unique" ON _PieceConstructeurs ("A", "B")');
$this->addSql('ALTER INDEX IF EXISTS idx_e94732e54ad0cf31 RENAME TO "_PieceConstructeurs_B_index"');
$this->addSql('ALTER INDEX IF EXISTS idx_e94732e5d3d99e8b RENAME TO IDX_E94732E5F88A743C');
$this->addSql('ALTER TABLE _ProductConstructeurs DROP CONSTRAINT IF EXISTS FK_CF7403FCD3D99E8B');
$this->addSql('ALTER TABLE _ProductConstructeurs DROP CONSTRAINT IF EXISTS FK_CF7403FC4AD0CF31');
$this->addSql('ALTER TABLE _ProductConstructeurs DROP CONSTRAINT IF EXISTS _ProductConstructeurs_pkey');
$this->addSql('ALTER TABLE _ProductConstructeurs ALTER "A" TYPE TEXT');
$this->addSql('ALTER TABLE _ProductConstructeurs ALTER "B" TYPE TEXT');
$this->addSql('ALTER TABLE _ProductConstructeurs ADD CONSTRAINT "_ProductConstructeurs_A_fkey" FOREIGN KEY ("A") REFERENCES products (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE _ProductConstructeurs ADD CONSTRAINT "_ProductConstructeurs_B_fkey" FOREIGN KEY ("B") REFERENCES constructeurs (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS "_ProductConstructeurs_AB_unique" ON _ProductConstructeurs ("A", "B")');
$this->addSql('ALTER INDEX IF EXISTS idx_cf7403fc4ad0cf31 RENAME TO "_ProductConstructeurs_B_index"');
$this->addSql('ALTER INDEX IF EXISTS idx_cf7403fcd3d99e8b RENAME TO IDX_CF7403FCF88A743C');
$this->addSql('ALTER TABLE composants DROP CONSTRAINT IF EXISTS FK_F95A3199CC8A4CEE');
$this->addSql('ALTER TABLE composants DROP CONSTRAINT IF EXISTS FK_F95A319936799605');
$this->addSql('ALTER TABLE composants ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE composants ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE composants ALTER reference TYPE TEXT');
$this->addSql('ALTER TABLE composants ALTER structure TYPE JSONB');
$this->addSql('ALTER TABLE composants ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE composants ALTER "typeComposantId" TYPE TEXT');
$this->addSql('ALTER TABLE composants ALTER "productId" TYPE TEXT');
$this->addSql('ALTER TABLE composants ADD CONSTRAINT "composants_productId_fkey" FOREIGN KEY ("productId") REFERENCES products (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE composants ADD CONSTRAINT "composants_typeComposantId_fkey" FOREIGN KEY ("typeComposantId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS uniq_f95a31995e237e06 RENAME TO composants_name_key');
$this->addSql('ALTER INDEX IF EXISTS idx_f95a319936799605 RENAME TO IDX_F95A319921C3CCFC');
$this->addSql('ALTER INDEX IF EXISTS idx_f95a3199cc8a4cee RENAME TO IDX_F95A31999FD7F38F');
$this->addSql('ALTER TABLE constructeurs ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE constructeurs ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE constructeurs ALTER email TYPE TEXT');
$this->addSql('ALTER TABLE constructeurs ALTER phone TYPE TEXT');
$this->addSql('ALTER TABLE constructeurs ALTER "createdAt" SET DEFAULT \'now()\'');
$this->addSql('ALTER INDEX IF EXISTS uniq_cc8d6f55e237e06 RENAME TO constructeurs_name_key');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF5C4A705F');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF633EC4FD');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF345EE564');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF3C6A9D1');
$this->addSql('ALTER TABLE custom_field_values DROP CONSTRAINT IF EXISTS FK_6B64D7FF36799605');
$this->addSql('ALTER TABLE custom_field_values ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE custom_field_values ALTER value TYPE TEXT');
$this->addSql('ALTER TABLE custom_field_values ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE custom_field_values ALTER "customFieldId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_field_values ALTER "machineId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_field_values ALTER "composantId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_field_values ALTER "pieceId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_field_values ALTER "productId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT "custom_field_values_composantId_fkey" FOREIGN KEY ("composantId") REFERENCES composants (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT "custom_field_values_customFieldId_fkey" FOREIGN KEY ("customFieldId") REFERENCES custom_fields (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT "custom_field_values_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT "custom_field_values_pieceId_fkey" FOREIGN KEY ("pieceId") REFERENCES pieces (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE custom_field_values ADD CONSTRAINT "custom_field_values_productId_fkey" FOREIGN KEY ("productId") REFERENCES products (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ff345ee564 RENAME TO IDX_6B64D7FFEA0A2B9E');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ff5c4a705f RENAME TO IDX_6B64D7FFDAC15D53');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ff633ec4fd RENAME TO IDX_6B64D7FF92F0F180');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ff3c6a9d1 RENAME TO IDX_6B64D7FFD999EB60');
$this->addSql('ALTER INDEX IF EXISTS idx_6b64d7ff36799605 RENAME TO IDX_6B64D7FF21C3CCFC');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378C2F024C2');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378CCC8A4CEE');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378C169F1CF6');
$this->addSql('ALTER TABLE custom_fields DROP CONSTRAINT IF EXISTS FK_4A48378C57B7763A');
$this->addSql('ALTER TABLE custom_fields ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ALTER type TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ALTER "defaultValue" TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ALTER options TYPE VARCHAR');
$this->addSql('ALTER TABLE custom_fields ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE custom_fields ALTER "typeMachineId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ALTER "typeComposantId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ALTER "typePieceId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ALTER "typeProductId" TYPE TEXT');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT "custom_fields_typeComposantId_fkey" FOREIGN KEY ("typeComposantId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT "custom_fields_typeMachineId_fkey" FOREIGN KEY ("typeMachineId") REFERENCES type_machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT "custom_fields_typePieceId_fkey" FOREIGN KEY ("typePieceId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE custom_fields ADD CONSTRAINT "custom_fields_typeProductId_fkey" FOREIGN KEY ("typeProductId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378ccc8a4cee RENAME TO IDX_4A48378C9FD7F38F');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378c2f024c2 RENAME TO IDX_4A48378C542108FE');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378c169f1cf6 RENAME TO IDX_4A48378CF429180F');
$this->addSql('ALTER INDEX IF EXISTS idx_4a48378c57b7763a RENAME TO IDX_4A48378CE7123582');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B07288633EC4FD');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B07288345EE564');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B072883C6A9D1');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B0728836799605');
$this->addSql('ALTER TABLE documents DROP CONSTRAINT IF EXISTS FK_A2B072886973A4FD');
$this->addSql('ALTER TABLE documents ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER filename TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER "mimeType" TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE documents ALTER "machineId" TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER "composantId" TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER "pieceId" TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER "productId" TYPE TEXT');
$this->addSql('ALTER TABLE documents ALTER "siteId" TYPE TEXT');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT "documents_composantId_fkey" FOREIGN KEY ("composantId") REFERENCES composants (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT "documents_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT "documents_pieceId_fkey" FOREIGN KEY ("pieceId") REFERENCES pieces (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT "documents_productId_fkey" FOREIGN KEY ("productId") REFERENCES products (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE documents ADD CONSTRAINT "documents_siteId_fkey" FOREIGN KEY ("siteId") REFERENCES sites (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b07288345ee564 RENAME TO IDX_A2B07288EA0A2B9E');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b07288633ec4fd RENAME TO IDX_A2B0728892F0F180');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b072883c6a9d1 RENAME TO IDX_A2B07288D999EB60');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b0728836799605 RENAME TO IDX_A2B0728821C3CCFC');
$this->addSql('ALTER INDEX IF EXISTS idx_a2b072886973a4fd RENAME TO IDX_A2B07288871A3650');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19633EC4FD');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19345EE564');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19EF6CF34B');
$this->addSql('ALTER TABLE machine_component_links DROP CONSTRAINT IF EXISTS FK_528EFE19C44B383C');
$this->addSql('ALTER TABLE machine_component_links ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE machine_component_links ALTER "nameOverride" TYPE TEXT');
$this->addSql('ALTER TABLE machine_component_links ALTER "referenceOverride" TYPE TEXT');
$this->addSql('ALTER TABLE machine_component_links ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE machine_component_links ALTER "machineId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_component_links ALTER "composantId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_component_links ALTER "parentLinkId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_component_links ALTER "typeMachineComponentRequirementId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT "machine_component_links_composantId_fkey" FOREIGN KEY ("composantId") REFERENCES composants (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT "machine_component_links_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT "machine_component_links_parentLinkId_fkey" FOREIGN KEY ("parentLinkId") REFERENCES machine_component_links (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_component_links ADD CONSTRAINT "machine_component_links_typeMachineComponentRequirementId_fkey" FOREIGN KEY ("typeMachineComponentRequirementId") REFERENCES type_machine_component_requirements (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe19345ee564 RENAME TO IDX_528EFE19EA0A2B9E');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe19633ec4fd RENAME TO IDX_528EFE1992F0F180');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe19ef6cf34b RENAME TO IDX_528EFE191446D9B2');
$this->addSql('ALTER INDEX IF EXISTS idx_528efe19c44b383c RENAME TO IDX_528EFE19BBF9038C');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_62941615633EC4FD');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_629416153C6A9D1');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_62941615EF6CF34B');
$this->addSql('ALTER TABLE machine_piece_links DROP CONSTRAINT IF EXISTS FK_62941615F957D314');
$this->addSql('ALTER TABLE machine_piece_links ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE machine_piece_links ALTER "nameOverride" TYPE TEXT');
$this->addSql('ALTER TABLE machine_piece_links ALTER "referenceOverride" TYPE TEXT');
$this->addSql('ALTER TABLE machine_piece_links ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE machine_piece_links ALTER "machineId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_piece_links ALTER "pieceId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_piece_links ALTER "parentLinkId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_piece_links ALTER "typeMachinePieceRequirementId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT "machine_piece_links_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT "machine_piece_links_parentLinkId_fkey" FOREIGN KEY ("parentLinkId") REFERENCES machine_component_links (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT "machine_piece_links_pieceId_fkey" FOREIGN KEY ("pieceId") REFERENCES pieces (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_piece_links ADD CONSTRAINT "machine_piece_links_typeMachinePieceRequirementId_fkey" FOREIGN KEY ("typeMachinePieceRequirementId") REFERENCES type_machine_piece_requirements (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_62941615633ec4fd RENAME TO IDX_6294161592F0F180');
$this->addSql('ALTER INDEX IF EXISTS idx_62941615ef6cf34b RENAME TO IDX_629416151446D9B2');
$this->addSql('ALTER INDEX IF EXISTS idx_629416153c6a9d1 RENAME TO IDX_62941615D999EB60');
$this->addSql('ALTER INDEX IF EXISTS idx_62941615f957d314 RENAME TO IDX_629416156E0F7201');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259633EC4FD');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC3225936799605');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259B590B209');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259EF6CF34B');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259A63AC5DC');
$this->addSql('ALTER TABLE machine_product_links DROP CONSTRAINT IF EXISTS FK_8CC32259937A1D7C');
$this->addSql('ALTER TABLE machine_product_links ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE machine_product_links ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE machine_product_links ALTER "machineId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_product_links ALTER "productId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_product_links ALTER "typeMachineProductRequirementId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_product_links ALTER "parentLinkId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_product_links ALTER "parentComponentLinkId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_product_links ALTER "parentPieceLinkId" TYPE TEXT');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT "machine_product_links_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT "machine_product_links_parentComponentLinkId_fkey" FOREIGN KEY ("parentComponentLinkId") REFERENCES machine_component_links (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT "machine_product_links_parentLinkId_fkey" FOREIGN KEY ("parentLinkId") REFERENCES machine_product_links (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT "machine_product_links_parentPieceLinkId_fkey" FOREIGN KEY ("parentPieceLinkId") REFERENCES machine_piece_links (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT "machine_product_links_productId_fkey" FOREIGN KEY ("productId") REFERENCES products (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machine_product_links ADD CONSTRAINT "machine_product_links_typeMachineProductRequirementId_fkey" FOREIGN KEY ("typeMachineProductRequirementId") REFERENCES type_machine_product_requirements (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259633ec4fd RENAME TO "machine_product_links_machineId_idx"');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc3225936799605 RENAME TO "machine_product_links_productId_idx"');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259a63ac5dc RENAME TO IDX_8CC32259BD5B4086');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259ef6cf34b RENAME TO IDX_8CC322591446D9B2');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259937a1d7c RENAME TO IDX_8CC32259B1619FA4');
$this->addSql('ALTER INDEX IF EXISTS idx_8cc32259b590b209 RENAME TO IDX_8CC32259187FC99C');
$this->addSql('ALTER TABLE machines DROP CONSTRAINT IF EXISTS FK_F1CE8DED6973A4FD');
$this->addSql('ALTER TABLE machines DROP CONSTRAINT IF EXISTS FK_F1CE8DED2F024C2');
$this->addSql('ALTER TABLE machines ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE machines ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE machines ALTER reference TYPE TEXT');
$this->addSql('ALTER TABLE machines ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE machines ALTER "siteId" TYPE TEXT');
$this->addSql('ALTER TABLE machines ALTER "typeMachineId" TYPE TEXT');
$this->addSql('ALTER TABLE machines ADD CONSTRAINT "machines_siteId_fkey" FOREIGN KEY ("siteId") REFERENCES sites (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE machines ADD CONSTRAINT "machines_typeMachineId_fkey" FOREIGN KEY ("typeMachineId") REFERENCES type_machines (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS uniq_f1ce8ded5e237e06 RENAME TO machines_name_key');
$this->addSql('ALTER INDEX IF EXISTS idx_f1ce8ded6973a4fd RENAME TO IDX_F1CE8DED871A3650');
$this->addSql('ALTER INDEX IF EXISTS idx_f1ce8ded2f024c2 RENAME TO IDX_F1CE8DED542108FE');
$this->addSql('ALTER TABLE pieces DROP CONSTRAINT IF EXISTS FK_B92D7472169F1CF6');
$this->addSql('ALTER TABLE pieces DROP CONSTRAINT IF EXISTS FK_B92D747236799605');
$this->addSql('ALTER TABLE pieces ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE pieces ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE pieces ALTER reference TYPE TEXT');
$this->addSql('ALTER TABLE pieces ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE pieces ALTER "typePieceId" TYPE TEXT');
$this->addSql('ALTER TABLE pieces ALTER "productId" TYPE TEXT');
$this->addSql('ALTER TABLE pieces ADD CONSTRAINT "pieces_productId_fkey" FOREIGN KEY ("productId") REFERENCES products (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE pieces ADD CONSTRAINT "pieces_typePieceId_fkey" FOREIGN KEY ("typePieceId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS uniq_b92d74725e237e06 RENAME TO pieces_name_key');
$this->addSql('ALTER INDEX IF EXISTS idx_b92d747236799605 RENAME TO IDX_B92D747221C3CCFC');
$this->addSql('ALTER INDEX IF EXISTS idx_b92d7472169f1cf6 RENAME TO IDX_B92D7472F429180F');
$this->addSql('ALTER TABLE products DROP CONSTRAINT IF EXISTS FK_B3BA5A5A57B7763A');
$this->addSql('ALTER TABLE products ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE products ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE products ALTER reference TYPE TEXT');
$this->addSql('ALTER TABLE products ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE products ALTER "typeProductId" TYPE TEXT');
$this->addSql('ALTER TABLE products ADD CONSTRAINT "products_typeProductId_fkey" FOREIGN KEY ("typeProductId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS uniq_b3ba5a5a5e237e06 RENAME TO products_name_key');
$this->addSql('ALTER INDEX IF EXISTS idx_b3ba5a5a57b7763a RENAME TO IDX_B3BA5A5AE7123582');
$this->addSql('DROP INDEX IF EXISTS UNIQ_email');
$this->addSql('ALTER TABLE profiles DROP COLUMN IF EXISTS email');
$this->addSql('ALTER TABLE profiles DROP COLUMN IF EXISTS roles');
$this->addSql('ALTER TABLE profiles DROP COLUMN IF EXISTS password');
$this->addSql('ALTER TABLE profiles ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE profiles ALTER "firstName" TYPE TEXT');
$this->addSql('ALTER TABLE profiles ALTER "lastName" TYPE TEXT');
$this->addSql('ALTER TABLE profiles ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE sites ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE sites ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE sites ALTER "contactName" TYPE TEXT');
$this->addSql('ALTER TABLE sites ALTER "contactPhone" TYPE TEXT');
$this->addSql('ALTER TABLE sites ALTER "contactAddress" TYPE TEXT');
$this->addSql('ALTER TABLE sites ALTER "contactPostalCode" TYPE TEXT');
$this->addSql('ALTER TABLE sites ALTER "contactCity" TYPE TEXT');
$this->addSql('ALTER TABLE sites ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE type_machine_component_requirements DROP CONSTRAINT IF EXISTS FK_969587902F024C2');
$this->addSql('ALTER TABLE type_machine_component_requirements DROP CONSTRAINT IF EXISTS FK_96958790CC8A4CEE');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER label TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER "typeMachineId" TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_component_requirements ALTER "typeComposantId" TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_component_requirements ADD CONSTRAINT "type_machine_component_requirements_typeComposantId_fkey" FOREIGN KEY ("typeComposantId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE RESTRICT NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE type_machine_component_requirements ADD CONSTRAINT "type_machine_component_requirements_typeMachineId_fkey" FOREIGN KEY ("typeMachineId") REFERENCES type_machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_96958790cc8a4cee RENAME TO IDX_969587909FD7F38F');
$this->addSql('ALTER INDEX IF EXISTS idx_969587902f024c2 RENAME TO IDX_96958790542108FE');
$this->addSql('ALTER TABLE type_machine_piece_requirements DROP CONSTRAINT IF EXISTS FK_F609E59E2F024C2');
$this->addSql('ALTER TABLE type_machine_piece_requirements DROP CONSTRAINT IF EXISTS FK_F609E59E169F1CF6');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER label TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER "typeMachineId" TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_piece_requirements ALTER "typePieceId" TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_piece_requirements ADD CONSTRAINT "type_machine_piece_requirements_typeMachineId_fkey" FOREIGN KEY ("typeMachineId") REFERENCES type_machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE type_machine_piece_requirements ADD CONSTRAINT "type_machine_piece_requirements_typePieceId_fkey" FOREIGN KEY ("typePieceId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE RESTRICT NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_f609e59e2f024c2 RENAME TO IDX_F609E59E542108FE');
$this->addSql('ALTER INDEX IF EXISTS idx_f609e59e169f1cf6 RENAME TO IDX_F609E59EF429180F');
$this->addSql('ALTER TABLE type_machine_product_requirements DROP CONSTRAINT IF EXISTS FK_29A51F982F024C2');
$this->addSql('ALTER TABLE type_machine_product_requirements DROP CONSTRAINT IF EXISTS FK_29A51F9857B7763A');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER label TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER "typeMachineId" TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_product_requirements ALTER "typeProductId" TYPE TEXT');
$this->addSql('ALTER TABLE type_machine_product_requirements ADD CONSTRAINT "type_machine_product_requirements_typeMachineId_fkey" FOREIGN KEY ("typeMachineId") REFERENCES type_machines (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE type_machine_product_requirements ADD CONSTRAINT "type_machine_product_requirements_typeProductId_fkey" FOREIGN KEY ("typeProductId") REFERENCES "ModelType" (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER INDEX IF EXISTS idx_29a51f982f024c2 RENAME TO IDX_29A51F98542108FE');
$this->addSql('ALTER INDEX IF EXISTS idx_29a51f9857b7763a RENAME TO IDX_29A51F98E7123582');
$this->addSql('ALTER TABLE type_machines ALTER id TYPE TEXT');
$this->addSql('ALTER TABLE type_machines ALTER name TYPE TEXT');
$this->addSql('ALTER TABLE type_machines ALTER category TYPE TEXT');
$this->addSql('ALTER TABLE type_machines ALTER "maintenanceFrequency" TYPE TEXT');
$this->addSql('ALTER TABLE type_machines ALTER components TYPE JSONB');
$this->addSql('ALTER TABLE type_machines ALTER "criticalParts" TYPE JSONB');
$this->addSql('ALTER TABLE type_machines ALTER "machinePieces" TYPE JSONB');
$this->addSql('ALTER TABLE type_machines ALTER specifications TYPE JSONB');
$this->addSql('ALTER TABLE type_machines ALTER "createdAt" SET DEFAULT CURRENT_TIMESTAMP');
$this->addSql('ALTER INDEX IF EXISTS uniq_3c31aa115e237e06 RENAME TO type_machines_name_key');
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260125102000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add productIds JSON column to pieces to support multiple product requirements.';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE pieces ADD productIds JSON DEFAULT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE pieces DROP productIds');
}
}

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261120120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add email column to profiles when missing.';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE profiles ADD COLUMN IF NOT EXISTS email VARCHAR(180) DEFAULT NULL');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS uniq_profiles_email ON profiles (email)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX IF EXISTS uniq_profiles_email');
$this->addSql('ALTER TABLE profiles DROP COLUMN IF EXISTS email');
}
}

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261120123000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Ensure profiles.email exists (camelCase schema).';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE public.profiles ADD COLUMN IF NOT EXISTS email VARCHAR(180) DEFAULT NULL');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS uniq_profiles_email ON public.profiles (email)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX IF EXISTS uniq_profiles_email');
$this->addSql('ALTER TABLE public.profiles DROP COLUMN IF EXISTS email');
}
}

View File

@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261120124000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Normalize profiles columns to camelCase (quoted identifiers).';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'firstname'
) THEN
ALTER TABLE public.profiles RENAME COLUMN firstname TO "firstName";
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'lastname'
) THEN
ALTER TABLE public.profiles RENAME COLUMN lastname TO "lastName";
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'isactive'
) THEN
ALTER TABLE public.profiles RENAME COLUMN isactive TO "isActive";
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'createdat'
) THEN
ALTER TABLE public.profiles RENAME COLUMN createdat TO "createdAt";
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'updatedat'
) THEN
ALTER TABLE public.profiles RENAME COLUMN updatedat TO "updatedAt";
END IF;
END $$;
SQL);
}
public function down(Schema $schema): void
{
$this->addSql(<<<'SQL'
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'firstName'
) THEN
ALTER TABLE public.profiles RENAME COLUMN "firstName" TO firstname;
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'lastName'
) THEN
ALTER TABLE public.profiles RENAME COLUMN "lastName" TO lastname;
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'isActive'
) THEN
ALTER TABLE public.profiles RENAME COLUMN "isActive" TO isactive;
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'createdAt'
) THEN
ALTER TABLE public.profiles RENAME COLUMN "createdAt" TO createdat;
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'profiles' AND column_name = 'updatedAt'
) THEN
ALTER TABLE public.profiles RENAME COLUMN "updatedAt" TO updatedat;
END IF;
END $$;
SQL);
}
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261120125000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add missing profile auth columns (email, roles, password).';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE public.profiles ADD COLUMN IF NOT EXISTS email VARCHAR(180) DEFAULT NULL');
$this->addSql('ALTER TABLE public.profiles ADD COLUMN IF NOT EXISTS roles JSON DEFAULT \'["ROLE_USER"]\' NOT NULL');
$this->addSql('ALTER TABLE public.profiles ADD COLUMN IF NOT EXISTS password VARCHAR(255) DEFAULT NULL');
$this->addSql('CREATE UNIQUE INDEX IF NOT EXISTS uniq_profiles_email ON public.profiles (email)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX IF EXISTS uniq_profiles_email');
$this->addSql('ALTER TABLE public.profiles DROP COLUMN IF EXISTS password');
$this->addSql('ALTER TABLE public.profiles DROP COLUMN IF EXISTS roles');
$this->addSql('ALTER TABLE public.profiles DROP COLUMN IF EXISTS email');
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261120131000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Normalize public schema identifiers to lowercase (tables + columns).';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
DO $$
DECLARE
r RECORD;
BEGIN
-- Special-case legacy table name from Prisma.
IF EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'ModelType'
) THEN
EXECUTE 'ALTER TABLE public."ModelType" RENAME TO model_types';
END IF;
-- Rename columns containing uppercase letters.
FOR r IN
SELECT table_name, column_name
FROM information_schema.columns
WHERE table_schema = 'public' AND column_name ~ '[A-Z]'
LOOP
EXECUTE format(
'ALTER TABLE public.%I RENAME COLUMN %I TO %I',
r.table_name,
r.column_name,
lower(r.column_name)
);
END LOOP;
-- Rename tables containing uppercase letters.
FOR r IN
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public' AND table_name ~ '[A-Z]'
LOOP
EXECUTE format(
'ALTER TABLE public.%I RENAME TO %I',
r.table_name,
lower(r.table_name)
);
END LOOP;
END $$;
SQL);
}
public function down(Schema $schema): void
{
// Irreversible: cannot restore original casing reliably.
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20261120140000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Convert custom_fields.options from text[] to json.';
}
public function up(Schema $schema): void
{
$this->addSql("ALTER TABLE custom_fields ALTER COLUMN options TYPE JSON USING to_json(options)");
}
public function down(Schema $schema): void
{
$this->addSql("ALTER TABLE custom_fields ALTER COLUMN options TYPE TEXT[] USING ARRAY(SELECT json_array_elements_text(options))");
}
}

View File

@@ -1,5 +1,5 @@
INSERT INTO public.profiles (id, firstname, lastname, isactive, createdat, updatedat)
INSERT INTO public.profiles (id, firstname, lastname, email, isactive, createdat, updatedat)
VALUES
('admin-default-profile', 'Admin', 'General', true, '2025-09-23 13:09:47.804', '2025-09-23 13:09:47.804'),
('cmhab2j3x003g47v77xhnm1ff', 'Elodie', 'Souriau', true, '2025-10-28 08:29:25.437', '2025-10-28 08:29:25.437')
('admin-default-profile', 'Admin', 'General', 'admin@admin.fr', true, '2025-09-23 13:09:47.804', '2025-09-23 13:09:47.804'),
('cmhab2j3x003g47v77xhnm1ff', 'Elodie', 'Souriau', 'elodie@gg.fr', true, '2025-10-28 08:29:25.437', '2025-10-28 08:29:25.437')
ON CONFLICT (id) DO NOTHING;

View File

@@ -0,0 +1,32 @@
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN
SELECT table_schema, table_name, column_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND column_name <> lower(column_name)
ORDER BY table_name, column_name
LOOP
-- Skip if a lowercase version already exists to avoid collisions.
IF EXISTS (
SELECT 1
FROM information_schema.columns c
WHERE c.table_schema = r.table_schema
AND c.table_name = r.table_name
AND c.column_name = lower(r.column_name)
) THEN
RAISE NOTICE 'Skip %.%: % -> % (target exists)', r.table_name, r.column_name, r.column_name, lower(r.column_name);
ELSE
EXECUTE format(
'ALTER TABLE %I.%I RENAME COLUMN %I TO %I',
r.table_schema,
r.table_name,
r.column_name,
lower(r.column_name)
);
RAISE NOTICE 'Renamed %.%: % -> %', r.table_name, r.column_name, r.column_name, lower(r.column_name);
END IF;
END LOOP;
END $$;

View File

@@ -1,74 +1,171 @@
#!/usr/bin/env python3
import re
import sys
INSERT_RE = re.compile(
r"(?P<prefix>INSERT\s+INTO\s+[^;]*?\()(?P<cols>[^)]*)(?P<suffix>\)\s+VALUES)",
re.IGNORECASE | re.DOTALL,
)
TABLE_RE = re.compile(
r"(?P<before>INSERT\s+INTO\s+)(?P<table>(?:\"[^\"]+\"\.|[A-Za-z_][\w$]*\.)?\"[^\"]+\"|(?:\"[^\"]+\"\.|[A-Za-z_][\w$]*\.)?[A-Za-z_][\w$]*)",
re.IGNORECASE,
)
CREATE_DB_RE = re.compile(r"^CREATE\s+DATABASE\s+.+?;$", re.IGNORECASE | re.MULTILINE)
CONNECT_RE = re.compile(r"^\\connect\\s+.+?$", re.IGNORECASE | re.MULTILINE)
TABLE_NAME_MAP = {
"ModelType": "model_types",
"TypeMachine": "type_machines",
"TypeMachineComponentRequirement": "type_machine_component_requirements",
"TypeMachinePieceRequirement": "type_machine_piece_requirements",
"TypeMachineProductRequirement": "type_machine_product_requirements",
"MachinePieceLink": "machine_piece_links",
"MachineComponentLink": "machine_component_links",
"MachineProductLink": "machine_product_links",
"Machine": "machines",
"Product": "products",
"Piece": "pieces",
"Composant": "composants",
"Profile": "profiles",
"CustomField": "custom_fields",
"CustomFieldValue": "custom_field_values",
"Document": "documents",
"Constructeur": "constructeurs",
"Site": "sites",
}
def normalize_identifiers(sql: str) -> str:
SKIP_TABLES = {
"_prisma_migrations",
}
def to_snake(name: str) -> str:
out = []
i = 0
in_single = False
length = len(sql)
while i < length:
ch = sql[i]
if in_single:
if ch == "'":
if i + 1 < length and sql[i + 1] == "'":
out.append("''")
i += 2
continue
in_single = False
length = len(name)
for i, ch in enumerate(name):
if ch.isupper():
prev = name[i - 1] if i > 0 else ""
nxt = name[i + 1] if i + 1 < length else ""
if i > 0 and (prev.islower() or prev.isdigit() or (prev.isupper() and nxt.islower())):
out.append("_")
out.append(ch.lower())
else:
out.append(ch)
i += 1
continue
return "".join(out)
if ch == "'":
in_single = True
out.append(ch)
i += 1
continue
if ch == '"':
i += 1
ident = []
while i < length:
if sql[i] == '"':
break
ident.append(sql[i])
i += 1
ident_str = ''.join(ident)
mapped = TABLE_NAME_MAP.get(ident_str)
if mapped is not None:
out.append(mapped)
else:
out.append(ident_str.lower())
if i < length and sql[i] == '"':
i += 1
continue
def to_lower_compact(name: str) -> str:
return name.replace("_", "").lower()
out.append(ch)
i += 1
return ''.join(out)
def remap_table(ident: str, mode: str) -> str:
mapped = TABLE_NAME_MAP.get(ident)
if mapped is not None:
return mapped
if mode == "snake":
return to_snake(ident)
if mode == "lower":
return to_lower_compact(ident)
raise ValueError(f"Unsupported mode: {mode}")
def extract_table_ident(prefix: str) -> str | None:
match = TABLE_RE.search(prefix)
if not match:
return None
table = match.group("table")
# Handle quoted schema like "public"."TableName"
if '"."' in table:
parts = table.split('"."', 1)
ident = parts[1].strip('"')
elif "." in table:
_, ident = table.split(".", 1)
ident = ident.strip('"')
else:
ident = table.strip('"')
return ident
def normalize_table_name(prefix: str, mode: str) -> str:
def repl(match: re.Match[str]) -> str:
table = match.group("table")
schema = ""
ident = table
# Handle quoted schema like "public"."TableName"
if '"."' in table:
parts = table.split('"."', 1)
schema_name = parts[0].strip('"')
ident = parts[1].strip('"')
schema = f'"{schema_name}".'
elif "." in table:
schema_part, ident = table.split(".", 1)
schema_name = schema_part.strip('"')
schema = f'"{schema_name}".'
ident = ident.strip('"')
else:
ident = table.strip('"')
mapped = remap_table(ident, mode)
return f'{match.group("before")}{schema}"{mapped}"'
return TABLE_RE.sub(repl, prefix)
def remap_columns(cols: str, mode: str) -> str:
def repl(match: re.Match[str]) -> str:
name = match.group(1)
if mode == "snake":
if any(ch.isupper() for ch in name):
return f"\"{to_snake(name)}\""
return match.group(0)
if mode == "lower":
return f"\"{to_lower_compact(name)}\""
raise ValueError(f"Unsupported mode: {mode}")
return re.sub(r"\"([^\"]+)\"", repl, cols)
def normalize_dump(sql: str, mode: str) -> str:
sql = CREATE_DB_RE.sub("", sql)
sql = CONNECT_RE.sub("", sql)
def repl(match: re.Match[str]) -> str:
raw_prefix = match.group("prefix")
ident = extract_table_ident(raw_prefix)
if ident is not None:
mapped = remap_table(ident, mode)
if ident in SKIP_TABLES or mapped in SKIP_TABLES:
return ""
prefix = normalize_table_name(raw_prefix, mode)
cols = remap_columns(match.group("cols"), mode)
return f"{prefix}{cols}{match.group('suffix')}"
return INSERT_RE.sub(repl, sql)
def main() -> int:
if len(sys.argv) != 3:
print("Usage: scripts/normalize-dump.py <input.sql> <output.sql>", file=sys.stderr)
if len(sys.argv) not in (3, 4):
print("Usage: scripts/normalize-dump.py <input.sql> <output.sql> [--snake|--lower]", file=sys.stderr)
return 1
src = sys.argv[1]
dst = sys.argv[2]
mode = "lower"
if len(sys.argv) == 4:
if sys.argv[3] == "--snake":
mode = "snake"
elif sys.argv[3] == "--lower":
mode = "lower"
else:
print("Invalid mode. Use --snake or --lower.", file=sys.stderr)
return 1
with open(src, "r", encoding="utf-8") as f:
data = f.read()
normalized = normalize_identifiers(data)
normalized = normalize_dump(data, mode)
with open(dst, "w", encoding="utf-8") as f:
f.write(normalized)

195
scripts/release.sh Executable file
View File

@@ -0,0 +1,195 @@
#!/bin/bash
set -e
# Couleurs pour l'affichage
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Répertoire racine du projet
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
VERSION_FILE="$PROJECT_ROOT/VERSION"
API_PLATFORM_FILE="$PROJECT_ROOT/config/packages/api_platform.yaml"
FRONTEND_DIR="$PROJECT_ROOT/Inventory_frontend"
# Lire la version actuelle
current_version=$(cat "$VERSION_FILE" | tr -d '\n')
# Fonction pour afficher l'aide
show_help() {
echo -e "${BLUE}Usage:${NC} $0 [version|bump_type]"
echo ""
echo "Arguments:"
echo " version Version spécifique (ex: 1.2.3)"
echo " bump_type Type de bump: major, minor, patch"
echo ""
echo "Exemples:"
echo " $0 1.0.0 # Définit la version à 1.0.0"
echo " $0 patch # 1.0.0 -> 1.0.1"
echo " $0 minor # 1.0.0 -> 1.1.0"
echo " $0 major # 1.0.0 -> 2.0.0"
echo ""
echo -e "Version actuelle: ${GREEN}$current_version${NC}"
}
# Fonction pour bumper la version
bump_version() {
local version=$1
local bump_type=$2
IFS='.' read -r major minor patch <<< "$version"
case $bump_type in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
echo "$major.$minor.$patch"
}
# Vérifier les arguments
if [ $# -eq 0 ]; then
show_help
exit 0
fi
arg=$1
# Déterminer la nouvelle version
case $arg in
major|minor|patch)
new_version=$(bump_version "$current_version" "$arg")
;;
-h|--help|help)
show_help
exit 0
;;
*)
# Vérifier le format de version (semver basique)
if [[ $arg =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
new_version=$arg
else
echo -e "${RED}Erreur:${NC} Format de version invalide: $arg"
echo "Utilisez le format X.Y.Z (ex: 1.2.3) ou major/minor/patch"
exit 1
fi
;;
esac
echo -e "${BLUE}Release v$new_version${NC}"
echo "================================"
echo -e "Version actuelle: ${YELLOW}$current_version${NC}"
echo -e "Nouvelle version: ${GREEN}$new_version${NC}"
echo ""
# Vérifier qu'on n'est pas sur une version identique
if [ "$current_version" = "$new_version" ]; then
echo -e "${YELLOW}La version est déjà $new_version${NC}"
exit 0
fi
# Demander confirmation
read -p "Continuer ? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Annulé."
exit 0
fi
cd "$PROJECT_ROOT"
# ===========================================
# ÉTAPE 1 : Gérer le submodule frontend
# ===========================================
echo ""
echo -e "${BLUE}[1/6]${NC} Vérification du submodule frontend..."
cd "$FRONTEND_DIR"
# Vérifier s'il y a des changements non commités dans le submodule
if ! git diff --quiet --exit-code || ! git diff --cached --quiet --exit-code; then
echo -e "${YELLOW}Changements détectés dans le submodule frontend${NC}"
git status --short
echo ""
read -p "Commiter ces changements dans le submodule ? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git add -A
git commit -m "chore(release): prepare v$new_version"
else
echo -e "${RED}Erreur:${NC} Veuillez d'abord commiter les changements du submodule."
exit 1
fi
fi
# ===========================================
# ÉTAPE 2 : Tag le submodule
# ===========================================
echo -e "${BLUE}[2/6]${NC} Création du tag v$new_version dans le submodule..."
# Vérifier si le tag existe déjà
if git rev-parse "v$new_version" >/dev/null 2>&1; then
echo -e "${YELLOW}Le tag v$new_version existe déjà dans le submodule${NC}"
else
git tag -a "v$new_version" -m "Release v$new_version"
echo -e "${GREEN}Tag v$new_version créé dans le submodule${NC}"
fi
# Retourner au projet principal
cd "$PROJECT_ROOT"
# ===========================================
# ÉTAPE 3 : Mettre à jour VERSION
# ===========================================
echo -e "${BLUE}[3/6]${NC} Mise à jour du fichier VERSION..."
echo "$new_version" > "$VERSION_FILE"
# ===========================================
# ÉTAPE 4 : Mettre à jour api_platform.yaml
# ===========================================
echo -e "${BLUE}[4/6]${NC} Mise à jour de api_platform.yaml..."
sed -i "s/version: .*/version: $new_version/" "$API_PLATFORM_FILE"
# ===========================================
# ÉTAPE 5 : Commit principal (avec mise à jour du submodule)
# ===========================================
echo -e "${BLUE}[5/6]${NC} Création du commit principal..."
git add "$VERSION_FILE" "$API_PLATFORM_FILE" "$FRONTEND_DIR"
git commit -m "chore(release): v$new_version"
# ===========================================
# ÉTAPE 6 : Tag principal
# ===========================================
echo -e "${BLUE}[6/6]${NC} Création du tag v$new_version..."
git tag -a "v$new_version" -m "Release v$new_version"
echo ""
echo -e "${GREEN}✓ Release v$new_version préparée avec succès !${NC}"
echo ""
echo "================================"
echo -e "${YELLOW}Prochaines étapes :${NC}"
echo ""
echo "1. Pousser le submodule frontend :"
echo -e " ${BLUE}cd Inventory_frontend && git push && git push --tags && cd ..${NC}"
echo ""
echo "2. Pousser le projet principal :"
echo -e " ${BLUE}git push && git push --tags${NC}"
echo ""
echo "3. Créer les releases sur Gitea :"
echo " - Inventory_frontend : tag v$new_version"
echo " - Inventory (backend) : tag v$new_version"
echo ""
echo "================================"

View File

@@ -400,18 +400,63 @@ class MachineSkeletonController extends AbstractController
private function normalizeMachine(Machine $machine): array
{
$site = $machine->getSite();
$typeMachine = $machine->getTypeMachine();
return [
'id' => $machine->getId(),
'name' => $machine->getName(),
'reference' => $machine->getReference(),
'prix' => $machine->getPrix(),
'siteId' => $machine->getSite()->getId(),
'typeMachineId' => $machine->getTypeMachine()?->getId(),
'siteId' => $site->getId(),
'site' => [
'id' => $site->getId(),
'name' => $site->getName(),
],
'typeMachineId' => $typeMachine?->getId(),
'typeMachine' => $typeMachine ? [
'id' => $typeMachine->getId(),
'name' => $typeMachine->getName(),
'category' => $typeMachine->getCategory(),
'description' => $typeMachine->getDescription(),
'customFields' => $this->normalizeCustomFields($typeMachine->getCustomFields()),
'componentRequirements' => $typeMachine->getComponentRequirements()
->map(fn (TypeMachineComponentRequirement $req) => $this->normalizeComponentRequirement($req))
->toArray(),
'pieceRequirements' => $typeMachine->getPieceRequirements()
->map(fn (TypeMachinePieceRequirement $req) => $this->normalizePieceRequirement($req))
->toArray(),
'productRequirements' => $typeMachine->getProductRequirements()
->map(fn (TypeMachineProductRequirement $req) => $this->normalizeProductRequirement($req))
->toArray(),
] : null,
'constructeurs' => $this->normalizeConstructeurs($machine->getConstructeurs()),
'documents' => null,
'customFieldValues' => null,
];
}
private function normalizeCustomFields(Collection $customFields): array
{
$items = [];
foreach ($customFields as $customField) {
if (!$customField instanceof CustomField) {
continue;
}
$items[] = [
'id' => $customField->getId(),
'name' => $customField->getName(),
'type' => $customField->getType(),
'required' => $customField->isRequired(),
'options' => $customField->getOptions(),
'defaultValue' => $customField->getDefaultValue(),
'orderIndex' => $customField->getOrderIndex(),
];
}
return $items;
}
private function normalizeComponentLinks(array $links): array
{
return array_map(function (MachineComponentLink $link): array {

View File

@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace App\Doctrine\QuoteStrategy;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\ORM\Internal\SQLResultCasing;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\JoinColumnMapping;
use Doctrine\ORM\Mapping\ManyToManyOwningSideMapping;
use Doctrine\ORM\Mapping\QuoteStrategy;
use function array_map;
use function array_merge;
use function assert;
use function explode;
use function implode;
/**
* Quote all identifiers to preserve camelCase column names in Postgres.
*/
final class AlwaysQuoteStrategy implements QuoteStrategy
{
use SQLResultCasing;
public function getColumnName(string $fieldName, ClassMetadata $class, AbstractPlatform $platform): string
{
return $platform->quoteSingleIdentifier($class->fieldMappings[$fieldName]->columnName);
}
public function getTableName(ClassMetadata $class, AbstractPlatform $platform): string
{
$tableName = $platform->quoteSingleIdentifier($class->table['name']);
if (! empty($class->table['schema'])) {
return $platform->quoteSingleIdentifier($class->table['schema']) . '.' . $tableName;
}
return $tableName;
}
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform): string
{
return implode('.', array_map(
static fn (string $part) => $platform->quoteSingleIdentifier($part),
explode('.', $definition['sequenceName']),
));
}
public function getJoinTableName(
ManyToManyOwningSideMapping $association,
ClassMetadata $class,
AbstractPlatform $platform,
): string {
$schema = '';
if (isset($association->joinTable->schema)) {
$schema = $platform->quoteSingleIdentifier($association->joinTable->schema) . '.';
}
return $schema . $platform->quoteSingleIdentifier($association->joinTable->name);
}
public function getJoinColumnName(JoinColumnMapping $joinColumn, ClassMetadata $class, AbstractPlatform $platform): string
{
return $platform->quoteSingleIdentifier($joinColumn->name);
}
public function getReferencedJoinColumnName(
JoinColumnMapping $joinColumn,
ClassMetadata $class,
AbstractPlatform $platform,
): string {
return $platform->quoteSingleIdentifier($joinColumn->referencedColumnName);
}
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform): array
{
$quotedColumnNames = [];
foreach ($class->identifier as $fieldName) {
if (isset($class->fieldMappings[$fieldName])) {
$quotedColumnNames[] = $this->getColumnName($fieldName, $class, $platform);
continue;
}
$assoc = $class->associationMappings[$fieldName];
assert($assoc->isToOneOwningSide());
$joinColumns = $assoc->joinColumns;
$assocQuotedColumnNames = array_map(
static fn (JoinColumnMapping $joinColumn) => $platform->quoteSingleIdentifier($joinColumn->name),
$joinColumns,
);
$quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames);
}
return $quotedColumnNames;
}
public function getColumnAlias(
string $columnName,
int $counter,
AbstractPlatform $platform,
ClassMetadata|null $class = null,
): string {
return $this->getSQLResultCasing($platform, $columnName . '_' . $counter);
}
}

View File

@@ -4,41 +4,59 @@ declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\ComposantRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: ComposantRepository::class)]
#[ORM\Table(name: 'composants')]
#[ORM\HasLifecycleCallbacks]
#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'reference' => 'partial', 'typeComposant' => 'exact'])]
#[ApiFilter(OrderFilter::class, properties: ['name', 'createdAt'])]
#[ApiResource(
normalizationContext: ['groups' => ['composant:read']],
paginationClientItemsPerPage: true,
paginationMaximumItemsPerPage: 500
)]
class Composant
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 36)]
#[Groups(['composant:read'])]
private ?string $id = null;
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
#[Groups(['composant:read'])]
private string $name;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['composant:read'])]
private ?string $reference = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
#[Groups(['composant:read'])]
private ?string $prix = null;
#[ORM\Column(type: Types::JSON, nullable: true)]
#[Groups(['composant:read'])]
private ?array $structure = null;
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'composants')]
#[ORM\JoinColumn(name: 'typeComposantId', referencedColumnName: 'id', nullable: true)]
#[Groups(['composant:read'])]
private ?ModelType $typeComposant = null;
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'composants')]
#[ORM\JoinColumn(name: 'productId', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
#[Groups(['composant:read'])]
private ?Product $product = null;
/**
@@ -50,18 +68,21 @@ class Composant
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
)]
#[Groups(['composant:read'])]
private Collection $constructeurs;
/**
* @var Collection<int, Document>
*/
#[ORM\OneToMany(mappedBy: 'composant', targetEntity: Document::class)]
#[Groups(['composant:read'])]
private Collection $documents;
/**
* @var Collection<int, CustomFieldValue>
*/
#[ORM\OneToMany(mappedBy: 'composant', targetEntity: CustomFieldValue::class)]
#[Groups(['composant:read'])]
private Collection $customFieldValues;
/**
@@ -71,27 +92,29 @@ class Composant
private Collection $machineLinks;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
private \DateTimeImmutable $createdAt;
#[Groups(['composant:read'])]
private DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
private \DateTimeImmutable $updatedAt;
#[Groups(['composant:read'])]
private DateTimeImmutable $updatedAt;
public function __construct()
{
$this->constructeurs = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->constructeurs = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->customFieldValues = new ArrayCollection();
$this->machineLinks = new ArrayCollection();
$this->machineLinks = new ArrayCollection();
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$now = new \DateTimeImmutable();
$now = new DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
if ($this->id === null) {
if (null === $this->id) {
$this->id = $this->generateCuid();
}
}
@@ -99,12 +122,7 @@ class Composant
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTimeImmutable();
}
private function generateCuid(): string
{
return 'cl' . bin2hex(random_bytes(12));
$this->updatedAt = new DateTimeImmutable();
}
public function getId(): ?string
@@ -199,6 +217,38 @@ class Composant
return $this->constructeurs;
}
/**
* @param iterable<Constructeur> $constructeurs
*/
public function setConstructeurs(iterable $constructeurs): static
{
$this->constructeurs = new ArrayCollection();
foreach ($constructeurs as $constructeur) {
if ($constructeur instanceof Constructeur && !$this->constructeurs->contains($constructeur)) {
$this->constructeurs->add($constructeur);
}
}
return $this;
}
public function addConstructeur(Constructeur $constructeur): static
{
if (!$this->constructeurs->contains($constructeur)) {
$this->constructeurs->add($constructeur);
}
return $this;
}
public function removeConstructeur(Constructeur $constructeur): static
{
$this->constructeurs->removeElement($constructeur);
return $this;
}
/**
* @return Collection<int, Document>
*/
@@ -215,13 +265,18 @@ class Composant
return $this->customFieldValues;
}
public function getCreatedAt(): \DateTimeImmutable
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
public function getUpdatedAt(): DateTimeImmutable
{
return $this->updatedAt;
}
private function generateCuid(): string
{
return 'cl'.bin2hex(random_bytes(12));
}
}

View File

@@ -6,6 +6,7 @@ namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\ConstructeurRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
@@ -14,7 +15,10 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ConstructeurRepository::class)]
#[ORM\Table(name: 'constructeurs')]
#[ORM\HasLifecycleCallbacks]
#[ApiResource]
#[ApiResource(
paginationClientItemsPerPage: true,
paginationMaximumItemsPerPage: 500
)]
class Constructeur
{
#[ORM\Id]
@@ -31,10 +35,10 @@ class Constructeur
private ?string $phone = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
private \DateTimeImmutable $createdAt;
private DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
private \DateTimeImmutable $updatedAt;
private DateTimeImmutable $updatedAt;
/**
* @var Collection<int, Machine>
@@ -62,20 +66,20 @@ class Constructeur
public function __construct()
{
$this->machines = new ArrayCollection();
$this->machines = new ArrayCollection();
$this->composants = new ArrayCollection();
$this->pieces = new ArrayCollection();
$this->products = new ArrayCollection();
$this->pieces = new ArrayCollection();
$this->products = new ArrayCollection();
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$now = new \DateTimeImmutable();
$now = new DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
if ($this->id === null) {
if (null === $this->id) {
$this->id = $this->generateCuid();
}
}
@@ -83,12 +87,7 @@ class Constructeur
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTimeImmutable();
}
private function generateCuid(): string
{
return 'cl' . bin2hex(random_bytes(12));
$this->updatedAt = new DateTimeImmutable();
}
public function getId(): ?string
@@ -139,13 +138,18 @@ class Constructeur
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
public function getUpdatedAt(): DateTimeImmutable
{
return $this->updatedAt;
}
private function generateCuid(): string
{
return 'cl'.bin2hex(random_bytes(12));
}
}

View File

@@ -179,6 +179,18 @@ class CustomField
return $this;
}
public function getTypeMachine(): ?TypeMachine
{
return $this->typeMachine;
}
public function setTypeMachine(?TypeMachine $typeMachine): static
{
$this->typeMachine = $typeMachine;
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;

View File

@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\ApiResource;
use App\Repository\DocumentRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: DocumentRepository::class)]
#[ORM\Table(name: 'documents')]
@@ -17,21 +18,27 @@ class Document
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 36)]
#[Groups(['document:read', 'composant:read', 'piece:read', 'product:read'])]
private ?string $id = null;
#[ORM\Column(type: Types::STRING, length: 255)]
#[Groups(['document:read', 'composant:read', 'piece:read', 'product:read'])]
private string $name;
#[ORM\Column(type: Types::STRING, length: 255)]
#[Groups(['document:read', 'composant:read', 'piece:read', 'product:read'])]
private string $filename;
#[ORM\Column(type: Types::TEXT)]
#[Groups(['document:read', 'composant:read', 'piece:read', 'product:read'])]
private string $path;
#[ORM\Column(type: Types::STRING, length: 100, name: 'mimeType')]
#[Groups(['document:read', 'composant:read', 'piece:read', 'product:read'])]
private string $mimeType;
#[ORM\Column(type: Types::INTEGER)]
#[Groups(['document:read', 'composant:read', 'piece:read', 'product:read'])]
private int $size;
#[ORM\ManyToOne(targetEntity: Machine::class, inversedBy: 'documents')]

View File

@@ -4,9 +4,12 @@ declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use App\Enum\ModelCategory;
use App\Repository\ModelTypeRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
@@ -17,48 +20,59 @@ use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Table(name: 'model_types')]
#[ORM\UniqueConstraint(name: 'unique_category_name', columns: ['category', 'name'])]
#[ORM\HasLifecycleCallbacks]
#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['category' => 'exact'])]
#[ApiResource(
paginationClientItemsPerPage: true,
paginationMaximumItemsPerPage: 500
)]
class ModelType
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 36)]
#[Groups(['type_machine:read'])]
#[Groups(['type_machine:read', 'model_type:read'])]
private ?string $id = null;
#[ORM\Column(type: Types::STRING, length: 120)]
#[Groups(['type_machine:read'])]
#[Groups(['type_machine:read', 'model_type:read', 'model_type:write'])]
private string $name;
#[ORM\Column(type: Types::STRING, length: 60, unique: true)]
#[Groups(['type_machine:read'])]
#[Groups(['type_machine:read', 'model_type:read', 'model_type:write'])]
private string $code;
#[ORM\Column(enumType: ModelCategory::class)]
#[Groups(['type_machine:read'])]
#[Groups(['type_machine:read', 'model_type:read', 'model_type:write'])]
private ModelCategory $category;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['type_machine:read'])]
#[Groups(['type_machine:read', 'model_type:read', 'model_type:write'])]
private ?string $notes = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['type_machine:read'])]
#[Groups(['type_machine:read', 'model_type:read', 'model_type:write'])]
private ?string $description = null;
#[ORM\Column(type: Types::JSON, nullable: true, name: 'componentSkeleton')]
#[Groups(['model_type:read'])]
private ?array $componentSkeleton = null;
#[ORM\Column(type: Types::JSON, nullable: true, name: 'pieceSkeleton')]
#[Groups(['model_type:read'])]
private ?array $pieceSkeleton = null;
#[ORM\Column(type: Types::JSON, nullable: true, name: 'productSkeleton')]
#[Groups(['model_type:read'])]
private ?array $productSkeleton = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
private \DateTimeImmutable $createdAt;
#[Groups(['model_type:read'])]
private DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
private \DateTimeImmutable $updatedAt;
#[Groups(['model_type:read'])]
private DateTimeImmutable $updatedAt;
private ?array $pendingStructure = null;
/**
* @var Collection<int, Composant>
@@ -116,25 +130,25 @@ class ModelType
public function __construct()
{
$this->composants = new ArrayCollection();
$this->pieces = new ArrayCollection();
$this->products = new ArrayCollection();
$this->composants = new ArrayCollection();
$this->pieces = new ArrayCollection();
$this->products = new ArrayCollection();
$this->componentRequirements = new ArrayCollection();
$this->pieceRequirements = new ArrayCollection();
$this->productRequirements = new ArrayCollection();
$this->customFields = new ArrayCollection();
$this->pieceCustomFields = new ArrayCollection();
$this->productCustomFields = new ArrayCollection();
$this->pieceRequirements = new ArrayCollection();
$this->productRequirements = new ArrayCollection();
$this->customFields = new ArrayCollection();
$this->pieceCustomFields = new ArrayCollection();
$this->productCustomFields = new ArrayCollection();
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$now = new \DateTimeImmutable();
$now = new DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
if ($this->id === null) {
if (null === $this->id) {
$this->id = $this->generateCuid();
}
}
@@ -142,12 +156,7 @@ class ModelType
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTimeImmutable();
}
private function generateCuid(): string
{
return 'cl' . bin2hex(random_bytes(12));
$this->updatedAt = new DateTimeImmutable();
}
public function getId(): ?string
@@ -195,6 +204,11 @@ class ModelType
{
$this->category = $category;
if (null !== $this->pendingStructure) {
$this->applyStructureForCategory($this->pendingStructure, $category);
$this->pendingStructure = null;
}
return $this;
}
@@ -258,13 +272,65 @@ class ModelType
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
#[Groups(['model_type:read'])]
public function getStructure(): ?array
{
return match ($this->category) {
ModelCategory::COMPONENT => $this->componentSkeleton,
ModelCategory::PIECE => $this->pieceSkeleton,
ModelCategory::PRODUCT => $this->productSkeleton,
};
}
#[Groups(['model_type:write'])]
public function setStructure(?array $structure): static
{
if (!isset($this->category)) {
$this->pendingStructure = $structure;
return $this;
}
$this->applyStructureForCategory($structure, $this->category);
return $this;
}
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
public function getUpdatedAt(): DateTimeImmutable
{
return $this->updatedAt;
}
private function generateCuid(): string
{
return 'cl'.bin2hex(random_bytes(12));
}
private function applyStructureForCategory(?array $structure, ModelCategory $category): void
{
if (ModelCategory::COMPONENT === $category) {
$this->componentSkeleton = $structure;
$this->pieceSkeleton = null;
$this->productSkeleton = null;
return;
}
if (ModelCategory::PIECE === $category) {
$this->pieceSkeleton = $structure;
$this->componentSkeleton = null;
$this->productSkeleton = null;
return;
}
$this->productSkeleton = $structure;
$this->componentSkeleton = null;
$this->pieceSkeleton = null;
}
}

View File

@@ -4,40 +4,61 @@ declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\PieceRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: PieceRepository::class)]
#[ORM\Table(name: 'pieces')]
#[ORM\HasLifecycleCallbacks]
#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'reference' => 'partial', 'typePiece' => 'exact'])]
#[ApiFilter(OrderFilter::class, properties: ['name', 'createdAt'])]
#[ApiResource(
normalizationContext: ['groups' => ['piece:read']],
paginationClientItemsPerPage: true,
paginationMaximumItemsPerPage: 500
)]
class Piece
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 36)]
#[Groups(['piece:read'])]
private ?string $id = null;
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
#[Groups(['piece:read'])]
private string $name;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['piece:read'])]
private ?string $reference = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
#[Groups(['piece:read'])]
private ?string $prix = null;
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'pieces')]
#[ORM\JoinColumn(name: 'typePieceId', referencedColumnName: 'id', nullable: true)]
#[Groups(['piece:read'])]
private ?ModelType $typePiece = null;
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'pieces')]
#[ORM\JoinColumn(name: 'productId', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
#[Groups(['piece:read'])]
private ?Product $product = null;
#[ORM\Column(type: Types::JSON, nullable: true, name: 'productIds')]
#[Groups(['piece:read'])]
private ?array $productIds = null;
/**
* @var Collection<int, Constructeur>
*/
@@ -47,18 +68,21 @@ class Piece
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
)]
#[Groups(['piece:read'])]
private Collection $constructeurs;
/**
* @var Collection<int, Document>
*/
#[ORM\OneToMany(mappedBy: 'piece', targetEntity: Document::class)]
#[Groups(['piece:read'])]
private Collection $documents;
/**
* @var Collection<int, CustomFieldValue>
*/
#[ORM\OneToMany(mappedBy: 'piece', targetEntity: CustomFieldValue::class)]
#[Groups(['piece:read'])]
private Collection $customFieldValues;
/**
@@ -68,27 +92,29 @@ class Piece
private Collection $machineLinks;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
private \DateTimeImmutable $createdAt;
#[Groups(['piece:read'])]
private DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
private \DateTimeImmutable $updatedAt;
#[Groups(['piece:read'])]
private DateTimeImmutable $updatedAt;
public function __construct()
{
$this->constructeurs = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->constructeurs = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->customFieldValues = new ArrayCollection();
$this->machineLinks = new ArrayCollection();
$this->machineLinks = new ArrayCollection();
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$now = new \DateTimeImmutable();
$now = new DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
if ($this->id === null) {
if (null === $this->id) {
$this->id = $this->generateCuid();
}
}
@@ -96,12 +122,7 @@ class Piece
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTimeImmutable();
}
private function generateCuid(): string
{
return 'cl' . bin2hex(random_bytes(12));
$this->updatedAt = new DateTimeImmutable();
}
public function getId(): ?string
@@ -173,6 +194,60 @@ class Piece
{
$this->product = $product;
if ($product && empty($this->productIds)) {
$productId = $product->getId();
$this->productIds = $productId ? [$productId] : null;
}
if (!$product && empty($this->productIds)) {
$this->productIds = null;
}
return $this;
}
/**
* @return string[]
*/
public function getProductIds(): array
{
if (!is_array($this->productIds)) {
return [];
}
return array_values(
array_filter(
array_map(
static fn ($value) => is_string($value) ? trim($value) : '',
$this->productIds,
),
static fn (string $value) => $value !== '',
),
);
}
public function setProductIds(?array $productIds): static
{
if (!is_array($productIds)) {
$this->productIds = null;
return $this;
}
$normalized = array_values(
array_unique(
array_filter(
array_map(
static fn ($value) => is_string($value) ? trim($value) : '',
$productIds,
),
static fn (string $value) => $value !== '',
),
),
);
$this->productIds = $normalized === [] ? null : $normalized;
return $this;
}
@@ -184,6 +259,22 @@ class Piece
return $this->constructeurs;
}
public function addConstructeur(Constructeur $constructeur): static
{
if (!$this->constructeurs->contains($constructeur)) {
$this->constructeurs->add($constructeur);
}
return $this;
}
public function removeConstructeur(Constructeur $constructeur): static
{
$this->constructeurs->removeElement($constructeur);
return $this;
}
/**
* @return Collection<int, Document>
*/
@@ -200,13 +291,18 @@ class Piece
return $this->customFieldValues;
}
public function getCreatedAt(): \DateTimeImmutable
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
public function getUpdatedAt(): DateTimeImmutable
{
return $this->updatedAt;
}
private function generateCuid(): string
{
return 'cl'.bin2hex(random_bytes(12));
}
}

View File

@@ -4,34 +4,50 @@ declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\ProductRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
#[ORM\Table(name: 'products')]
#[ORM\HasLifecycleCallbacks]
#[ApiResource]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'partial', 'reference' => 'partial', 'typeProduct' => 'exact'])]
#[ApiFilter(OrderFilter::class, properties: ['name', 'createdAt'])]
#[ApiResource(
normalizationContext: ['groups' => ['product:read']],
paginationClientItemsPerPage: true,
paginationMaximumItemsPerPage: 500
)]
class Product
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 36)]
#[Groups(['product:read'])]
private ?string $id = null;
#[ORM\Column(type: Types::STRING, length: 255, unique: true)]
#[Groups(['product:read'])]
private string $name;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['product:read'])]
private ?string $reference = null;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true, name: 'supplierPrice')]
#[Groups(['product:read'])]
private ?string $supplierPrice = null;
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'products')]
#[ORM\JoinColumn(name: 'typeProductId', referencedColumnName: 'id', nullable: true)]
#[Groups(['product:read'])]
private ?ModelType $typeProduct = null;
/**
@@ -43,18 +59,21 @@ class Product
joinColumns: [new ORM\JoinColumn(name: 'A', referencedColumnName: 'id', onDelete: 'CASCADE')],
inverseJoinColumns: [new ORM\InverseJoinColumn(name: 'B', referencedColumnName: 'id', onDelete: 'CASCADE')]
)]
#[Groups(['product:read'])]
private Collection $constructeurs;
/**
* @var Collection<int, Document>
*/
#[ORM\OneToMany(mappedBy: 'product', targetEntity: Document::class)]
#[Groups(['product:read'])]
private Collection $documents;
/**
* @var Collection<int, CustomFieldValue>
*/
#[ORM\OneToMany(mappedBy: 'product', targetEntity: CustomFieldValue::class)]
#[Groups(['product:read'])]
private Collection $customFieldValues;
/**
@@ -76,29 +95,31 @@ class Product
private Collection $machineLinks;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
private \DateTimeImmutable $createdAt;
#[Groups(['product:read'])]
private DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
private \DateTimeImmutable $updatedAt;
#[Groups(['product:read'])]
private DateTimeImmutable $updatedAt;
public function __construct()
{
$this->constructeurs = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->constructeurs = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->customFieldValues = new ArrayCollection();
$this->pieces = new ArrayCollection();
$this->composants = new ArrayCollection();
$this->machineLinks = new ArrayCollection();
$this->pieces = new ArrayCollection();
$this->composants = new ArrayCollection();
$this->machineLinks = new ArrayCollection();
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$now = new \DateTimeImmutable();
$now = new DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
if ($this->id === null) {
if (null === $this->id) {
$this->id = $this->generateCuid();
}
}
@@ -106,12 +127,7 @@ class Product
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTimeImmutable();
}
private function generateCuid(): string
{
return 'cl' . bin2hex(random_bytes(12));
$this->updatedAt = new DateTimeImmutable();
}
public function getId(): ?string
@@ -182,6 +198,22 @@ class Product
return $this->constructeurs;
}
public function addConstructeur(Constructeur $constructeur): static
{
if (!$this->constructeurs->contains($constructeur)) {
$this->constructeurs->add($constructeur);
}
return $this;
}
public function removeConstructeur(Constructeur $constructeur): static
{
$this->constructeurs->removeElement($constructeur);
return $this;
}
/**
* @return Collection<int, Document>
*/
@@ -198,13 +230,18 @@ class Product
return $this->customFieldValues;
}
public function getCreatedAt(): \DateTimeImmutable
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
public function getUpdatedAt(): DateTimeImmutable
{
return $this->updatedAt;
}
private function generateCuid(): string
{
return 'cl'.bin2hex(random_bytes(12));
}
}

View File

@@ -45,17 +45,17 @@ class Profile implements UserInterface, PasswordAuthenticatedUserInterface
#[Groups(['profile:read', 'profile:write'])]
private ?string $email = null;
#[ORM\Column(type: 'string', length: 100, name: 'firstName')]
#[ORM\Column(type: 'string', length: 100, name: 'firstname')]
#[Assert\NotBlank]
#[Groups(['profile:read', 'profile:write'])]
private string $firstName;
#[ORM\Column(type: 'string', length: 100, name: 'lastName')]
#[ORM\Column(type: 'string', length: 100, name: 'lastname')]
#[Assert\NotBlank]
#[Groups(['profile:read', 'profile:write'])]
private string $lastName;
#[ORM\Column(type: 'boolean', options: ['default' => true], name: 'isActive')]
#[ORM\Column(type: 'boolean', options: ['default' => true], name: 'isactive')]
#[Groups(['profile:read', 'profile:write'])]
private bool $isActive = true;
@@ -73,11 +73,11 @@ class Profile implements UserInterface, PasswordAuthenticatedUserInterface
#[Groups(['profile:write'])]
private ?string $password = null;
#[ORM\Column(type: 'datetime_immutable', name: 'createdAt')]
#[ORM\Column(type: 'datetime_immutable', name: 'createdat')]
#[Groups(['profile:read'])]
private DateTimeImmutable $createdAt;
#[ORM\Column(type: 'datetime_immutable', name: 'updatedAt')]
#[ORM\Column(type: 'datetime_immutable', name: 'updatedat')]
#[Groups(['profile:read'])]
private DateTimeImmutable $updatedAt;

View File

@@ -11,6 +11,7 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Repository\SiteRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
@@ -27,7 +28,9 @@ use Symfony\Component\Validator\Constraints as Assert;
new Post(),
new Put(),
new Delete(),
]
],
paginationClientItemsPerPage: true,
paginationMaximumItemsPerPage: 500
)]
class Site
{
@@ -55,10 +58,10 @@ class Site
private string $contactCity = '';
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
private \DateTimeImmutable $createdAt;
private DateTimeImmutable $createdAt;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
private \DateTimeImmutable $updatedAt;
private DateTimeImmutable $updatedAt;
/**
* @var Collection<int, Machine>
@@ -74,18 +77,18 @@ class Site
public function __construct()
{
$this->machines = new ArrayCollection();
$this->machines = new ArrayCollection();
$this->documents = new ArrayCollection();
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$this->createdAt = new DateTimeImmutable();
$this->updatedAt = new DateTimeImmutable();
// Générer un ID CUID-compatible si nécessaire
if ($this->id === null) {
if (null === $this->id) {
$this->id = $this->generateCuid();
}
}
@@ -93,13 +96,7 @@ class Site
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTimeImmutable();
}
private function generateCuid(): string
{
// Génération d'un ID compatible CUID (format: cl + 24 caractères)
return 'cl' . bin2hex(random_bytes(12));
$this->updatedAt = new DateTimeImmutable();
}
// Getters et Setters
@@ -188,12 +185,12 @@ class Site
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): \DateTimeImmutable
public function getUpdatedAt(): DateTimeImmutable
{
return $this->updatedAt;
}
@@ -257,4 +254,10 @@ class Site
return $this;
}
private function generateCuid(): string
{
// Génération d'un ID compatible CUID (format: cl + 24 caractères)
return 'cl'.bin2hex(random_bytes(12));
}
}

View File

@@ -32,7 +32,9 @@ use Symfony\Component\Validator\Constraints as Assert;
new Post(),
new Put(),
new Delete(),
]
],
paginationClientItemsPerPage: true,
paginationMaximumItemsPerPage: 500
)]
class TypeMachine
{
@@ -50,7 +52,7 @@ class TypeMachine
#[Groups(['type_machine:read', 'type_machine:write'])]
private ?string $description = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true, name: 'maintenanceFrequency')]
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
#[Groups(['type_machine:read', 'type_machine:write'])]
private ?string $category = null;
@@ -58,11 +60,11 @@ class TypeMachine
#[Groups(['type_machine:read', 'type_machine:write'])]
private ?string $maintenanceFrequency = null;
#[ORM\Column(type: Types::JSON, nullable: true, name: 'criticalParts')]
#[ORM\Column(type: Types::JSON, nullable: true)]
#[Groups(['type_machine:read', 'type_machine:write'])]
private ?array $components = null;
#[ORM\Column(type: Types::JSON, nullable: true, name: 'machinePieces')]
#[ORM\Column(type: Types::JSON, nullable: true)]
#[Groups(['type_machine:read', 'type_machine:write'])]
private ?array $criticalParts = null;
@@ -91,40 +93,41 @@ class TypeMachine
/**
* @var Collection<int, CustomField>
*/
#[ORM\OneToMany(targetEntity: CustomField::class, mappedBy: 'typeMachine')]
#[ORM\OneToMany(targetEntity: CustomField::class, mappedBy: 'typeMachine', cascade: ['persist', 'remove'])]
#[ApiProperty(readableLink: true, writableLink: true)]
private Collection $customFields;
/**
* @var Collection<int, TypeMachineComponentRequirement>
*/
#[ORM\OneToMany(targetEntity: TypeMachineComponentRequirement::class, mappedBy: 'typeMachine', cascade: ['persist', 'remove'])]
#[ApiProperty(readableLink: true)]
#[ApiProperty(readableLink: true, writableLink: true)]
private Collection $componentRequirements;
/**
* @var Collection<int, TypeMachinePieceRequirement>
*/
#[ORM\OneToMany(targetEntity: TypeMachinePieceRequirement::class, mappedBy: 'typeMachine', cascade: ['persist', 'remove'])]
#[ApiProperty(readableLink: true)]
#[ApiProperty(readableLink: true, writableLink: true)]
private Collection $pieceRequirements;
/**
* @var Collection<int, TypeMachineProductRequirement>
*/
#[ORM\OneToMany(targetEntity: TypeMachineProductRequirement::class, mappedBy: 'typeMachine', cascade: ['persist', 'remove'])]
#[ApiProperty(readableLink: true)]
#[ApiProperty(readableLink: true, writableLink: true)]
private Collection $productRequirements;
public function __construct()
{
$this->id = 'cl' . bin2hex(random_bytes(12));
$this->createdAt = new DateTimeImmutable();
$this->updatedAt = new DateTimeImmutable();
$this->machines = new ArrayCollection();
$this->customFields = new ArrayCollection();
$this->id = 'cl'.bin2hex(random_bytes(12));
$this->createdAt = new DateTimeImmutable();
$this->updatedAt = new DateTimeImmutable();
$this->machines = new ArrayCollection();
$this->customFields = new ArrayCollection();
$this->componentRequirements = new ArrayCollection();
$this->pieceRequirements = new ArrayCollection();
$this->productRequirements = new ArrayCollection();
$this->pieceRequirements = new ArrayCollection();
$this->productRequirements = new ArrayCollection();
}
public function getId(): ?string

View File

@@ -55,6 +55,7 @@ class TypeMachineComponentRequirement
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'componentRequirements')]
#[ORM\JoinColumn(name: 'typeComposantId', referencedColumnName: 'id', nullable: false)]
#[ApiProperty(readableLink: true)]
#[Groups(['type_machine:read'])]
private ModelType $typeComposant;
/**

View File

@@ -55,6 +55,7 @@ class TypeMachinePieceRequirement
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'pieceRequirements')]
#[ORM\JoinColumn(name: 'typePieceId', referencedColumnName: 'id', nullable: false)]
#[ApiProperty(readableLink: true)]
#[Groups(['type_machine:read'])]
private ModelType $typePiece;
/**

View File

@@ -55,6 +55,7 @@ class TypeMachineProductRequirement
#[ORM\ManyToOne(targetEntity: ModelType::class, inversedBy: 'productRequirements')]
#[ORM\JoinColumn(name: 'typeProductId', referencedColumnName: 'id', nullable: false)]
#[ApiProperty(readableLink: true)]
#[Groups(['type_machine:read'])]
private ModelType $typeProduct;
/**

View File

@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace App\EventSubscriber;
use App\Entity\Piece;
use App\Repository\ProductRepository;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Events;
/**
* Keep the legacy single product relation in sync with the new productIds array.
*/
final class PieceProductSyncSubscriber implements EventSubscriber
{
public function __construct(private readonly ProductRepository $productRepository)
{
}
public function getSubscribedEvents(): array
{
return [
Events::prePersist,
Events::preUpdate,
];
}
public function prePersist(LifecycleEventArgs $args): void
{
$entity = $args->getObject();
if (!$entity instanceof Piece) {
return;
}
$this->syncPrimaryProduct($entity);
}
public function preUpdate(PreUpdateEventArgs $args): void
{
$entity = $args->getObject();
if (!$entity instanceof Piece) {
return;
}
$this->syncPrimaryProduct($entity);
$em = $args->getObjectManager();
$meta = $em->getClassMetadata(Piece::class);
$em->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $entity);
}
private function syncPrimaryProduct(Piece $piece): void
{
$productIds = $piece->getProductIds();
if ($productIds === []) {
// If no explicit list is provided, keep the legacy relation as-is.
return;
}
$primaryId = $productIds[0] ?? null;
if (!$primaryId) {
$piece->setProduct(null);
return;
}
$currentProductId = $piece->getProduct()?->getId();
if ($currentProductId === $primaryId) {
return;
}
$primaryProduct = $this->productRepository->find($primaryId);
$piece->setProduct($primaryProduct);
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\EventSubscriber;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
final class UniqueConstraintSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => 'onKernelException',
];
}
public function onKernelException(ExceptionEvent $event): void
{
$exception = $this->findUniqueConstraintViolation($event->getThrowable());
if (!$exception) {
return;
}
$event->setResponse(new JsonResponse(
[
'success' => false,
'error' => 'nom duplique',
],
JsonResponse::HTTP_CONFLICT
));
}
private function findUniqueConstraintViolation(\Throwable $throwable): ?UniqueConstraintViolationException
{
for ($current = $throwable; $current !== null; $current = $current->getPrevious()) {
if ($current instanceof UniqueConstraintViolationException) {
return $current;
}
}
return null;
}
}