Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have many schema I wish to compare, SQL::Translator::Manual shows this example sqlt-diff foo-v1.sql=MySQL foo-v2.sql=Oracle > diff.sql. How do I generate schemas required for foo-v1.sql and foo-v2.sql?

Replies are listed 'Best First'.
Re: SQL::Translator, sqlt-diff confusion
by marto (Cardinal) on Oct 02, 2014 at 13:03 UTC

    Use your database product to create a dump of each schema. For MySQL mysqldump:

    mysqldump --no-data --no-create-db

    Oracle has exp/imp tools and/or datapump, depending on which version you run. Your database documentation should point the way to the correct export tool.

    Update: slight rewording, my brain isn't working very well today.

Re: SQL::Translator, sqlt-diff confusion
by ww (Archbishop) on Oct 02, 2014 at 11:32 UTC
    Perhaps, read the documentation with the module?
    Or if your question is more basic (how do I write Perl code?), then Learning Perl (from O'Reilly) would be a good place to start.
    If neither of the above apply, then please read (at least) On asking for help and How do I post a question effectively?. Then you can edit your question to show what you've tried and to tell us how it fails.

    We're here to help you learn (master) Perl; NOT to write code for you.



    check Ln42!

      The question is specific, and not covered in the docs that I can see. I'm asking one specific thing, not for people to write a script for me. It's ok to pass a post by if you don't know the answer. It looks like you decided I was lazy without even taking your own advice. Anonymous posters can't "edit" their questions, have you read the perl monks documentation?

        The doc:

        FINDING THE DIFFERENCES BETWEEN TWO SCHEMAS ^
        
        As mentioned above, the "sqlt-diff" schema examines two schemas and creates SQL schema modification statements that can be used to transform the first schema into the second. The flag syntax is somewhat quirky:
        
          $ sqlt-diff foo-v1.sql=MySQL foo-v2.sql=Oracle > diff.sql
        
        As demonstrated, the schemas need not even be from the same vendor, though this is likely to produce some spurious results as datatypes are not currently viewed equivalent unless they match exactly, even if they would be converted to the same. For example, MySQL's "integer" data type would be converted to Oracle's "number," but the differ isn't quite smart enough yet to figure this out. Also, as the SQL to ALTER a field definition varies from database vendor to vendor, these statements are made using just the keyword "CHANGE" and will likely need to be corrected for the target database.

        It appears to me that the modification statements will provide information one-SMOP from that for which you've asked (i.e., some further effort required; batteries not included).

        Update: And if that's not the solution, there are several other sections of the doc (manual) that look relevant, including "EXTRACT SQL SCHEMAS DIRECTLY FROM DATABASE," "AUTOMATED CODE-GENERATION" and 'SQLFAIRY SCRIPTS" (which refers you to separate perldocs for several possibly useful approaches).


        ++$anecdote ne $data


        It looks like you decided I was lazy

        The root node looks lazy and doesn't have any really good replies yet because it's two sentences in one paragraph, doesn't show input, code, output, error messages, it doesn't describe what has been tried, or what the bigger picture is, and is missing details like: what databases?

        To put it more briefly, it doesn't follow the guidelines from How do I post a question effectively? and related nodes on getting help effectively, so the reference to the PerlMonks documentation is pretty ironic.

Re: SQL::Translator, sqlt-diff confusion, how to write/generate source schemas
by Anonymous Monk on Oct 02, 2014 at 22:59 UTC
    SQL::Translator, sqlt-diff confusion I have many schema I wish to compare,
    SQL::Translator::Manual shows this example sqlt-diff foo-v1.sql=MySQL foo-v2.sql=Oracle > diff.sql.

    How do I generate schemas required for foo-v1.sql and foo-v2.sql?

    What do you mean ? schema are something you write (or someone gives you)

    If you have an existing database and you can connect to it with sqlt as documented :)

    the short docs

    DBI Parser Options: sqlt -f|--from|--parser MySQL -t|--to|--producer Oracle [options] file [file2 ...] --dsn DSN for connecting to database (see also --use-same-auth below) --db-user Database user --db-password Database password

    Which you can use like

    The long better docs https://metacpan.org/pod/distribution/SQL-Translator/lib/SQL/Translator/Manual.pod#EXTRACT-SQL-SCHEMAS-DIRECTLY-FROM-DATABASE

    $ sqlt -f DBI --dsn dbi:mysql:FOO --db-user guest \ --db-password p4ssw0rd -t PostgreSQL > foo

    This usage is waaay easier :)

    $ sqlt -f DBI --db-user "" --db-password "" --dsn dbi:SQLite:dbidbd.an +ydata.tsv.temp.sqlite -t Oracle -- -- Created by SQL::Translator::Producer::Oracle -- Created on Thu Oct 2 16:07:59 2014 -- -- -- Table: trains --; CREATE TABLE "trains" ( "A" clob NOT NULL, "B" clob NOT NULL, "C" real NOT NULL, "D" clob NOT NULL, "E" clob NOT NULL, "F" real NOT NULL, "G" real NOT NULL ); / $ sqlt -f DBI --db-user "" --db-password "" --dsn dbi:SQLite:dbidbd.an +ydata.tsv.temp.sqlite -t Sybase -- -- Created by SQL::Translator::Producer::Sybase -- Created on Thu Oct 2 16:08:02 2014 -- -- -- Table: trains -- CREATE TABLE trains ( A varchar(255) NOT NULL, B varchar(255) NOT NULL, C double precision NOT NULL, D varchar(255) NOT NULL, E varchar(255) NOT NULL, F double precision NOT NULL, G double precision NOT NULL ); $ sqlt -f DBI --db-user "" --db-password "" --dsn dbi:SQLite:dbidbd.an +ydata.tsv.temp.sqlite -t MySQL -- -- Created by SQL::Translator::Producer::MySQL -- Created on Thu Oct 2 16:08:07 2014 -- SET foreign_key_checks=0; -- -- Table: `trains` -- CREATE TABLE `trains` ( `A` text NOT NULL, `B` text NOT NULL, `C` double NOT NULL, `D` text NOT NULL, `E` text NOT NULL, `F` double NOT NULL, `G` double NOT NULL ); SET foreign_key_checks=1;