Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration #46

Open
testlorenzospa opened this issue Nov 18, 2022 · 7 comments
Open

Migration #46

testlorenzospa opened this issue Nov 18, 2022 · 7 comments

Comments

@testlorenzospa
Copy link

Hello.

I want to use this library.
But I don't understant something.

If I already have a database (that I don't want to reset) can I update it using this library without a base SLQ script? If yes, how?

Thansk.

@byjg
Copy link
Owner

byjg commented Nov 18, 2022

It is possible. You can use the migration-cli project to help you set up manually.

Install migration-cli in an empty folder:

composer require byjg/migration-cli

Set up your environment variables

export MIGRATE_CONNECTION=<YOUR CONNECTION>
export MIGRATE_PATH=/path/to/migrate_files
export MIGRATE_DISABLE_RESET=true

Create an empty migration structure (it will create a base.sql, migrations/up/0001.sql and migrations/down/0000.sql)

./vendor/bin/migrate create $MIGRATE_PATH

Install the migration in the database:

./vendor/bin/migrate install

Now you can edit the file migrations/up/0001.sql with migrations content and run

./vendor/bin/migrate up -vvv

./vendor/bin/migrate version   # Check the migration was successfully applied

@testlorenzospa
Copy link
Author

Hello @byjg

Thanks for your solution.

However, seeing the code I have found another solution.

The migration object include a parameter for ignore the base script. Therefore, I have set this parameter as false like in the below instruction

$migration = new \ByJG\DbMigration\Migration($connectionUri, '/forlder/for/migration', false);

After that, I have use these two instruction

$migration->createVersion(); $migration->update($upVersion = null);

With the first instruction, the table migration is create.
With the second instruction, I can update the database without recreate it.

Is it acceptable as a solution?

There is a documentation about this library with property and methods explained? If yes, where can I find it?

Thanks again.

@byjg
Copy link
Owner

byjg commented Nov 21, 2022 via email

@Makennsky
Copy link

@byjg I have question about supporting of cross-database migration, I mean do some stuff with data from two or more source, it is available with that library?

@byjg
Copy link
Owner

byjg commented Dec 19, 2023

You can have as many sources you want, since each one has your OWN directory structure for migration.

e.g.

<?php
$migration1 = new \ByJG\DbMigration\Migration($connectionUri-1, '/forlder/for/migration-1');
$migration1->update();

$migration2 = new \ByJG\DbMigration\Migration($connectionUri-2, '/forlder/for/migration-2');
$migration2->update();

We don't have a single migration file doing different sources.

Do you have a use case I can consider?

@Makennsky
Copy link

@byjg Hello! I mean can we fetch data from one database and based on foreign key relation do update in second database within one migration file?

@byjg
Copy link
Owner

byjg commented Dec 20, 2023

It is possible if:

  • both databases are in the same server;
  • the user you are using has select grants on both databases

e.g.

insert into firstdb.table select * from seconddb.table;

NOTE:

  • Besides the migration can be used to gather information, its first use case is to run DDL commands (CREATE, ALTER, DROP, etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants