mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-17 15:49:34 +00:00
Made DBMigrationCommand take a DB url so we do not need a special doctrine config
This commit is contained in:
parent
00b35e3306
commit
d385303a52
3 changed files with 79 additions and 50 deletions
|
|
@ -1,56 +1,61 @@
|
||||||
doctrine:
|
doctrine:
|
||||||
dbal:
|
dbal:
|
||||||
# 1. GLOBAL SETTINGS (Apply to all connections)
|
url: '%env(resolve:DATABASE_URL)%'
|
||||||
|
|
||||||
|
# Required for DAMA doctrine test bundle
|
||||||
|
use_savepoints: true
|
||||||
|
|
||||||
|
# IMPORTANT: You MUST configure your server version,
|
||||||
|
# either here or in the DATABASE_URL env var (see .env file)
|
||||||
|
|
||||||
types:
|
types:
|
||||||
datetime: App\Doctrine\Types\UTCDateTimeType
|
# UTC datetimes
|
||||||
date: App\Doctrine\Types\UTCDateTimeType
|
datetime:
|
||||||
datetime_immutable: App\Doctrine\Types\UTCDateTimeImmutableType
|
class: App\Doctrine\Types\UTCDateTimeType
|
||||||
date_immutable: App\Doctrine\Types\UTCDateTimeImmutableType
|
date:
|
||||||
big_decimal: App\Doctrine\Types\BigDecimalType
|
class: App\Doctrine\Types\UTCDateTimeType
|
||||||
tinyint: App\Doctrine\Types\TinyIntType
|
|
||||||
|
|
||||||
connections:
|
datetime_immutable:
|
||||||
default:
|
class: App\Doctrine\Types\UTCDateTimeImmutableType
|
||||||
use_savepoints: true
|
date_immutable:
|
||||||
schema_filter: ~^(?!internal)~
|
class: App\Doctrine\Types\UTCDateTimeImmutableType
|
||||||
url: '%env(resolve:DATABASE_URL)%'
|
|
||||||
|
|
||||||
migration_source:
|
big_decimal:
|
||||||
use_savepoints: true
|
class: App\Doctrine\Types\BigDecimalType
|
||||||
schema_filter: ~^(?!internal)~
|
tinyint:
|
||||||
url: '%env(resolve:DB_MIGRATION_SOURCE)%'
|
class: App\Doctrine\Types\TinyIntType
|
||||||
|
|
||||||
|
schema_filter: ~^(?!internal)~
|
||||||
|
# Only enable this when needed
|
||||||
|
profiling_collect_backtrace: false
|
||||||
|
|
||||||
orm:
|
orm:
|
||||||
auto_generate_proxy_classes: true
|
auto_generate_proxy_classes: true
|
||||||
enable_lazy_ghost_objects: true
|
enable_lazy_ghost_objects: true
|
||||||
|
report_fields_where_declared: true
|
||||||
|
validate_xml_mapping: true
|
||||||
|
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
|
||||||
|
identity_generation_preferences:
|
||||||
|
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
|
||||||
|
auto_mapping: true
|
||||||
|
controller_resolver:
|
||||||
|
auto_mapping: true
|
||||||
|
mappings:
|
||||||
|
App:
|
||||||
|
type: attribute
|
||||||
|
is_bundle: false
|
||||||
|
dir: '%kernel.project_dir%/src/Entity'
|
||||||
|
prefix: 'App\Entity'
|
||||||
|
alias: App
|
||||||
|
|
||||||
entity_managers:
|
dql:
|
||||||
default: &common_orm_settings
|
string_functions:
|
||||||
report_fields_where_declared: true
|
regexp: App\Doctrine\Functions\Regexp
|
||||||
validate_xml_mapping: true
|
field: DoctrineExtensions\Query\Mysql\Field
|
||||||
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
|
field2: App\Doctrine\Functions\Field2
|
||||||
identity_generation_preferences:
|
natsort: App\Doctrine\Functions\Natsort
|
||||||
Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity
|
array_position: App\Doctrine\Functions\ArrayPosition
|
||||||
mappings:
|
ilike: App\Doctrine\Functions\ILike
|
||||||
App:
|
|
||||||
type: attribute
|
|
||||||
is_bundle: false
|
|
||||||
dir: '%kernel.project_dir%/src/Entity'
|
|
||||||
prefix: 'App\Entity'
|
|
||||||
alias: App
|
|
||||||
dql:
|
|
||||||
string_functions:
|
|
||||||
regexp: App\Doctrine\Functions\Regexp
|
|
||||||
field: DoctrineExtensions\Query\Mysql\Field
|
|
||||||
field2: App\Doctrine\Functions\Field2
|
|
||||||
natsort: App\Doctrine\Functions\Natsort
|
|
||||||
array_position: App\Doctrine\Functions\ArrayPosition
|
|
||||||
ilike: App\Doctrine\Functions\ILike
|
|
||||||
connection: default
|
|
||||||
|
|
||||||
migration_source:
|
|
||||||
<<: *common_orm_settings
|
|
||||||
connection: migration_source
|
|
||||||
|
|
||||||
when@test:
|
when@test:
|
||||||
doctrine:
|
doctrine:
|
||||||
|
|
|
||||||
|
|
@ -1622,6 +1622,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||||
* flysystem?: array{
|
* flysystem?: array{
|
||||||
* filesystem_service: scalar|null|Param,
|
* filesystem_service: scalar|null|Param,
|
||||||
* },
|
* },
|
||||||
|
* asset_mapper?: array<mixed>,
|
||||||
* chain?: array{
|
* chain?: array{
|
||||||
* loaders: list<scalar|null|Param>,
|
* loaders: list<scalar|null|Param>,
|
||||||
* },
|
* },
|
||||||
|
|
@ -2301,11 +2302,13 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||||
* controllers_json?: scalar|null|Param, // Default: "%kernel.project_dir%/assets/controllers.json"
|
* controllers_json?: scalar|null|Param, // Default: "%kernel.project_dir%/assets/controllers.json"
|
||||||
* }
|
* }
|
||||||
* @psalm-type UxTranslatorConfig = array{
|
* @psalm-type UxTranslatorConfig = array{
|
||||||
* dump_directory?: scalar|null|Param, // Default: "%kernel.project_dir%/var/translations"
|
* dump_directory?: scalar|null|Param, // The directory where translations and TypeScript types are dumped. // Default: "%kernel.project_dir%/var/translations"
|
||||||
|
* dump_typescript?: bool|Param, // Control whether TypeScript types are dumped alongside translations. Disable this if you do not use TypeScript (e.g. in production when using AssetMapper). // Default: true
|
||||||
* domains?: string|array{ // List of domains to include/exclude from the generated translations. Prefix with a `!` to exclude a domain.
|
* domains?: string|array{ // List of domains to include/exclude from the generated translations. Prefix with a `!` to exclude a domain.
|
||||||
* type?: scalar|null|Param,
|
* type?: scalar|null|Param,
|
||||||
* elements?: list<scalar|null|Param>,
|
* elements?: list<scalar|null|Param>,
|
||||||
* },
|
* },
|
||||||
|
* keys_patterns?: list<scalar|null|Param>,
|
||||||
* }
|
* }
|
||||||
* @psalm-type DompdfFontLoaderConfig = array{
|
* @psalm-type DompdfFontLoaderConfig = array{
|
||||||
* autodiscovery?: bool|array{
|
* autodiscovery?: bool|array{
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,11 @@ namespace App\Command\Migrations;
|
||||||
use App\DataTables\Helpers\ColumnSortHelper;
|
use App\DataTables\Helpers\ColumnSortHelper;
|
||||||
use App\Entity\Parts\Manufacturer;
|
use App\Entity\Parts\Manufacturer;
|
||||||
use App\Services\ImportExportSystem\PartKeeprImporter\PKImportHelper;
|
use App\Services\ImportExportSystem\PartKeeprImporter\PKImportHelper;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\ConnectionFactory;
|
||||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||||
|
use Doctrine\DBAL\Tools\DsnParser;
|
||||||
|
use Doctrine\ORM\EntityManager;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
use Doctrine\ORM\Id\AssignedGenerator;
|
use Doctrine\ORM\Id\AssignedGenerator;
|
||||||
|
|
@ -36,6 +39,7 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
@ -43,23 +47,40 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
#[AsCommand('partdb:migrate-db', 'Migrate the database to a different platform')]
|
#[AsCommand('partdb:migrate-db', 'Migrate the database to a different platform')]
|
||||||
class DBMigrationCommand extends Command
|
class DBMigrationCommand extends Command
|
||||||
{
|
{
|
||||||
private readonly EntityManagerInterface $sourceEM;
|
private ?EntityManagerInterface $sourceEM = null;
|
||||||
private readonly EntityManagerInterface $targetEM;
|
|
||||||
|
|
||||||
public function __construct(private readonly ManagerRegistry $managerRegistry,
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $targetEM,
|
||||||
private readonly PKImportHelper $importHelper,
|
private readonly PKImportHelper $importHelper,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->sourceEM = $this->managerRegistry->getManager('migration_source');
|
|
||||||
$this->targetEM = $this->managerRegistry->getManager('default');
|
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function configure(): void
|
||||||
|
{
|
||||||
|
$this->
|
||||||
|
addArgument('url', InputArgument::REQUIRED, 'The database connection URL of the source database to migrate from');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a source EntityManager based on the given connection URL
|
||||||
|
* @param string $url
|
||||||
|
* @return EntityManagerInterface
|
||||||
|
*/
|
||||||
|
private function getSourceEm(string $url): EntityManagerInterface
|
||||||
|
{
|
||||||
|
$connectionFactory = new ConnectionFactory();
|
||||||
|
$connection = $connectionFactory->createConnection(['url' => $url]);
|
||||||
|
return new EntityManager($connection, $this->targetEM->getConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output): int
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
$this->sourceEM = $this->getSourceEm($input->getArgument('url'));
|
||||||
|
|
||||||
// Example migration logic (to be replaced with actual migration code)
|
// Example migration logic (to be replaced with actual migration code)
|
||||||
$io->info('Starting database migration...');
|
$io->info('Starting database migration...');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue