Sign inSign up

bbkr2/uprooted

By bbkr2

•Updated almost 4 years ago

Extract subtrees of data from relational databases.

Image
0

1.0K

bbkr2/uprooted repository overview

⁠UpRooted - utility to extract subtrees of data from relational databases.

Tree of data may be for example some user account and all records in related tables that belong to him. Useful for cases like:

  • Transferring users between database shards for better load balancing.
  • Cloning user data from production environment to devel to debug some issues in isolated manner.
  • Saving user state for backup or legal purposes.

For full documentation see README⁠.

⁠Sample scenario

You have MySQL database and you need to extract user from users table having id = 1 with all his data from related tables.

Create working directory for scripts and output files, for example:

mkdir /Users/me/uprooted

Run Docker and mount this directory.

docker run --interactive --tty --volume /Users/me/uprooted:/home/uprooted bbkr2/uprooted:latest

Create example.raku file in this directory with following content (adjust lines marked with comments):

use DBIish;
my $connection = DBIish.connect(
    'mysql',
    host => '***', port => 3306, user => '***', password => '***', database => '***'    # adjust connection credentials
);

use UpRooted::Schema::MySQL;
my $schema = UpRooted::Schema::MySQL.new( :$connection );

use UpRooted::Tree;
my $tree = UpRooted::Tree.new( root-table => $schema.table( 'users' ) );    # adjust table name

use UpRooted::Reader::MySQL;
my $reader = UpRooted::Reader::MySQL.new( :$connection, :$tree );

use UpRooted::Writer::MySQLFile;
my $writer = UpRooted::Writer::MySQLFile.new;
    
$writer.write( $reader, id => 1 );    # adjust Primary Key / Unique Key field name

Run your script:

raku example.raku

Your user will be saved to out.sql file in /Users/me/uprooted directory.

⁠Issues

If you run into a problem with UpRooted please report it⁠.

Tag summary

Content type

Image

Digest

sha256:7fd35d2f5…

Size

245 MB

Last updated

almost 4 years ago

docker pull bbkr2/uprooted