Sqitch - single plan row, multiple sql files - sqitch

I'm looking to move to sqitch, but my team likes their migrations as multiple files. That is, for example, if we create a foreign key and create an index in the same jira ticket, we like PROJ-123-create-fk.sql and PROJ-123-create-index.sql.
I'd like to keep a single row in the sqitch.plan file, so that each jira ticket corresponds to a single row.
Basically, short of adding lines to sqitch.plan, can I do this? Is there a way to "include" other sql files from a master one? Something like
PROJ-123-main.sql
\include PROJ-123-create-fk.sql
\include PROJ-123-create-index.sql
Thanks so much!

The \ir psql directive solved this for me.
in PROJ-123-deploy.sql
\ir PROJ-123-create-fk.sql
\ir PROJ-123-create-index.sql
If the fk and index sql files are in the same directory, they will be executed.

Since you want to store it as a single line in the plan file, it doesn't quite match, but I will explain the method we use below. Maybe there are parts that you want to use in it.
There is a similar situation in my team, but we use sqitch tags. Each version of our application corresponds to a subtask. And each task corresponds to a tag. We create sql files as many as the number of subtasks. Then we combine them in a tag that we created with the name of the main task. In our CI/CD pipeline that we use for the database, we also provide the transition between versions with tags. I wanted to add this method here in case anyone prefers to use a similar structure.
Simple example;
Let's have v2.0 of our application installed and a new table and an index are required for v2.1
We create two subtasks named create table and create index under the main task named v2.1
We create two sql files;
app_v2.1_table_create.sql to create a table, app_v2.1_index_create.sql to create an index.
After that, we create a sqitch tag called v2.1. Notice it has the same name as the main task.

Related

Create table using description from the file

Case:
I have csv data extract to be loaded with a great COPY INTO and also have a csv file with table description.
I want to create table from this description file before loading data.
Q:Is it possible to create a table by using description file?
I looked at 'CREATE TABLE mytable FROM LOADER myloader();' example but it does not seem support additional attributes to define columns.
One solution I know is to create a Python function to parse file and generate ddl statement but was curios if it can be done easier way.
Idea for enhancement: COPY INTO would be expanded to support creating tables at the same time by adding description file as another parameter.
Unfortunately, this is not currently possible.
The problem from my experience with implementing this kind of convenience feature is that it would be difficult to define a syntax that:
is backward compatible so that it does not break existing code
convenient for a majority of users
simple enough to implement

ODI 11g Interface SQL Data to Multiple Flat Files

Is it possible to create an ODI interface that creates multiple flat files based off unique records in a SQL table? There is plenty of information out there regarding how to interface multiple flat files into one SQL datastore - but is it possible the other way around?
Not sure we can tell the interface to create dynamic models based off when certain SQL data primary key data value change for example on a given table? So 600 records with 600 different data points at the PK column corresponding to 600 different rows creates 600 flat files?
Just typing this makes me think the answer is a FIRM NO.
I think you can do it.
Minimal steps with minimal informations:
Create a Package;
Create a loop in the package (For i = 0; i
Inside the loop you will setup the name of the file that will be generate (variable);
Still inside the loop, setup the filter that is used into the interface (variable);
Still inside the loop, run the interface.
Additional setup.
For the interface you will need two models:
for the source
for the target
In the model of the target (Technology File) you will need to setup the name of the file. Instead a static name, you will put a project/global variable. That variable you will setup during the loop. So, each time you will loop, you will have a different name.
I tried to be clear and short in the same time. I can expand my explication and give you an example.
If I didn't understood well, please tell me.

How can I go back to a migration with Flyway?

Let's assume that we have 2 scripts.
One that will create a table (ex: Students) and is named as V1_Students_create.sql and another one named V2_Students_Create.sql that will create a second table (ex: Teachers). After I have migrated to the second version, how can I go back to the first migration (the one where I have executed the first script - V1_Students_create.sql) and have only the first table (Students) created ?
I am using an Oracle database.
Thank you
Currently you cannot go back or downgrade your migration. There is an issue created for this feature and a lot of discussions are going on that, but still nothing. Here is the link for the issue: https://github.com/flyway/flyway/issues/109

Joomla: regenerate aliases for all articles at once?

I am working on a Joomla 3.2.1 site and the client, without thinking, entered in the same alias for all articles, instead of letting the system use the article title. So now if I want to turn on SEF URL's we are going to have 404 issues in the future.
I want to resave or regenerate all article aliases at once (batch).
Is there a way to do it? in the MYSQL DB maybe?
Thank you in advance.
$alias = JApplication::stringURLSafe($article->title);
Joomla will generate the alias when saving the article. I am not aware of any batch joomla feature to regenerate all the aliases and I would also be interested to know about this.
If no other batch solution exists, you should do manually the updates to these fields.
In the database, you could run update queries for all your articles, but you must type each update query one by one.
The update query for a single row would look like:
UPDATE jos_content
SET alias='my-new-alias-name'
WHERE id='{id-of-the-article}'
For multiple rows at once, you could do something like this:
UPDATE jos_content
SET alias = CASE id
WHEN 1 THEN 'alias1'
WHEN 2 THEN 'alias2'
WHEN 3 THEN 'alias3'
END
WHERE id IN (1,2,3)
What you could do is delete the alias data from all of your articles in the database using mysql. Then make a tag, like "fixalias." Using the batch processing feature tag all of the articles with that tag.
This will run store() for all of your articles and automatically generate the aliases. Then delete the tag from the tag manager.you ar
A similar strategy would involve also deleting all the aliases but batch moving (don't copy) your articles to a temporary category and then moving them back.

Saving copy of old table entry to another table when updating table entry with SaveChanges()?

Im working on an online store project where I have already made it possible for an administrator to update different table entries via the store gui (like items, user profiles, orders etc). SaveChanges(); is used to save the changes.
Im currently trying to figure out how to make this work:
An entry in table "items" gets updated.
Before the entry in the table "items" gets updated, a copy of the old entry gets saved into a table named "history-items".
The copy that is saved to "history-items" preferably has a timestamp.
How would I go about doing this? (As you might tell, I just recently picked up visual studio, and am pretty new to everything)
Thank you.
There are atleast 3 ways to do this:
If you are using SQL Server 2008 or newer this is now built in functionality, see: http://msdn.microsoft.com/en-us/library/bb933994.aspx
If you opt not to use that then the simplest solution is to use database triggers.
If you want to do it in C# code, then you need to read the original values before saving, and save these original values to the history table. For reading original values see: How to get original values of an entity in Entity Framework?
I would go for option 1 if possible.

Resources