Save Scrips to version control

I have a growing collection of “User Defined”-Scrips. Is there a good way to serialize these to some text files so I can put them in a git repo and sync them back into RT after modifying them?

Cheers,
Vinzenz

1 Like

Hi Vinzenz,

Yes, you’ll want to do what we do for core RT conditions and actions. You can create a .pm file under the proper namespace and then use an initialdata to create the database entry in the condition or action table. There’s an extension RT::Extension::AdminConditionsAndActions which replaces that last step with an admin UI right in RT.

Best,
Shawn

Hi Shawn,

I can import initialdata with rt-setup-database --action insert --datafile initialdata right? Will this update existing actions / conditions / scrips?

Thanks,
Vinzenz

I have a growing collection of “User Defined”-Scrips. Is there a good
way to serialize these to some text files so I can put them in a git
repo and sync them back into RT after modifying them?

It would be nice to be able to “export” a custom Scrip/Template from the
RT database into a proper RT Extension as if it was created by
Module::Install::RTx from the beginning. The result would probably have
to be adjusted manually, but having customisation properly packaged,
could facilitate sharing.

  • Vegard V -
2 Likes

Yes.

No, it will probably insert duplicates rather than updating existing records.

We’ve been working on a feature along these lines. We’ll have more news once we’ve documented and published, but in the meantime check out the 4.4/serialize-json-initialdata branch: https://github.com/bestpractical/rt/compare/4.4/serialize-json-initialdata

So how do I update an existing record?

What exactly do you want to update? If it’s the code for the condition or action, then you can just update the .pm file and you don’t need to worry about touching the database.

Err, I somehow thought everything would land in the db… Thanks for reminding me :smiley: Let’s see how I can apply this to my scrip-jungle

This is what I use to backup my scripts


#!/bin/bash

cd "$(dirname $(readlink -f $0))"

IFS="
"

for line in $( mysql --skip-column-names --batch --execute "select id, Description from Scrips order by id" rtdb )
do
        IFS="   " read id des <<< "$line"
        # replace whitespaces by underline
        file=${des// /_}.txt
        mysql --skip-column-names --batch --execute "select * from Scrips where id='$id' order by id\G" rtdb > "$file"
done

git commit -a -m "$(date "+%F %T")"
1 Like