SQL::Tr...Globals(3)

🌸 NAME 🌸

okay bestie, welcome to SQL::Tr...Globals(3) from the User Contributed Perl Documentation β€” yes, that manual name is doing the absolute most, but we move. The actual icon here is SQL::Translator::Filter::Globals β€” Add global fields and indices to all tables. πŸ’…

✨ SYNOPSIS ✨

Here's the canonical usage, and I'm keeping every character exactly as it is (including the 'modifed' spelling β€” not me fixing it, we respect the original):

  # e.g. Add timestamp field to all tables.
  use SQL::Translator;

  my $sqlt = SQL::Translator->new(
      from => 'MySQL',
      to   => 'MySQL',
      filters => [
        Globals => {
            fields => [
                {
                    name => 'modified'
                    data_type => 'TIMESTAMP'
                }
            ],
            indices => [
                {
                    fields => 'modifed',
                },
            ]
            constraints => [
                {
                }
            ]
        },
      ],
  ) || die "SQLFairy error : ".SQL::Translator->error;
  my $sql = $sqlt->translate || die "SQLFairy error : ".$sqlt->error;

πŸ’– DESCRIPTION πŸ’–

This filter literally adds global fields, indices and constraints to all tables in the schema. You can define the globals either in the filter args or by using a _GLOBAL_ table (peep below for that whole situation). And if a table already contains a field with the same name as a global? It gets skipped for that table. No cap. It's giving "set it once, apply everywhere," and honestly? Obsessed.

πŸ¦‹ The _GLOBAL_ Table πŸ¦‹

An alternative to using the args is to add a table called "_GLOBAL_" to the schema and then just use the filter. Any fields and indices defined on this table get added to all the tables in the schema, and then the _GLOBAL_ table is removed. The name of the global can be changed using a "global_table" arg to the filter. Cute, right? Slay. πŸŽ€

πŸ‘€ SEE ALSO πŸ‘€

πŸ’€ BUGS πŸ’€

  • It will generate duplicate indices if an index already exists on a table the same as one added globally. πŸ’€
  • It will generate duplicate constraints if a constraint already exists on a table the same as one added globally. πŸ’€

πŸ“ TODO πŸ“

Some extra data values that can be used to control the global addition. e.g. 'skip_global'.

🫢 AUTHOR 🫢

Mark Addison <grommit@users.sourceforge.net> β€” iconic behavior only. 🌟


okay that's the whole vibe. This page is from perl v5.42.0, dated 2024-12-12, and the title is SQL::Tr...Globals(3) β€” bye bestie, drink water and commit your changes πŸ’–βœ¨

πŸ“¦ where this page comes from