Skip to content

037 Auto create SQL updates for Componets in JCB

Amigo edited this page Jul 26, 2019 · 11 revisions

AUTO CREATE SQL UPDATES FOR COMPONENTS IN JCB

Views Are Linked To Set Of Tables

00:00:00

I would like to demonstrate one of the latest features that has been added to JCB. A feature request had been made: "Auto generate update SQL?". After a lengthy discussion the decision was made to add the feature and now it is basically done. First, some background regarding it. When a component is created in Joomla, you have a set of views, and these views and the back end are linked to a set of tables.

JCB Builds tables For Views On Installation

00:00:38

On the installation of the component, for example, as is done with JCB, it builds the tables for those views on installation. So if you go to the back end of the component, and create a new item, it stores the value in the database, that it can be retrieved. 00:01:17 As a developer make a change to this component which involves new tables, extra script need to be added to the components package upon installation. If it finds that there is already an existing component, it will update the database accordingly to the new settings, the new tables or any fields added. <<<<<<<<<<

Manually Adding New SQL Statements

We going to demonstrate this. 00:01:47 In JCB there used to be a way to do that, which still works. A way for you to manually add the new SQL statements that are needed to make the update, it was done under version updates tab. You would click on version updates tab and you would add your specific SQL query script, and upon installation if the existing version is below this update, it will grab this and install it into the database creating the new tables.

Adding A New View/New Table To Component

What I'm going to do now is, you'll see that at the moment, this admin view has only 1, 2, 3, 4, 5, 6, 00:02:38 views. I'm going to add another view to settings component. You can see it doesn't have these buttons ticked. I don't not know how to resolve this. It seems like it is a Joomla problem. Because there are multiple columns in this view. If you close it and click it again it fixes that anyway. I'm going to add a new view 00:03:09 called help documents and make some minor changes to the defaults. Add it to the 7th position, click save and click save again. We add a new view which means a new table to the database. We haven't written any of the SQL, because with the new changes this is going to be done for you automatically on the moment you compile this component. We are going again and compile this component. You will see it's version, it is still 1.4.1. 00:03:49 We compiling it.

System Checking The History If There Is A New Table

Now what the system is doing, it is checking the history and it's making a lot of calculation to dynamically realize that there is been a new table increment the version number. If I now install this component, I go and open that component. I'll see that the new view is here, if I open the view there is no errors. 00:04:20 If I create new, it'll automatically start behaving the way that is expected. Let say, text 'hi' we are targeting the external sources. 00:04:43 You can see the database already stores the values, and the new table is therefore in the database and working as expected. You realize that this means that our JCB component has been updated. If I refresh this page, you'll see that the version number has been incremented. 00:05:14 And if you open the version updates and scroll down you would see that 1.4.1 got this new creating of a help document table. And a new version(1.4.2) got allocated. We do not know what is this (https//github.com/SermonDisributor) link and so we add this (https//domain.com/.zip) demo link here which you need to manually update still. That is by far a tremendous improvement. 00:05:44

Adding New Field To Existing View

This also works not only with the adding of a new view, but also if you were to add a field to an existing view. Let me demonstrate that quickly. I'm going to be adding a new field to the preacher view. I'm simply going to select any fields since I will removed it again. Let's call it image. I'm going to add in field - image, Allignment - left in tab, order in edit - 2. 00:06:27 Save. Save and close. Now I've added a new field to preachers, and again I'll be going to the compiler, I'll select the component and compile. Again since it detected there's been a field changed, it incremented the version number. If I install the component and we go to the component, to the preachers view, we'll now see 00:07:02 that new field is there, image. If I was to select an image, and save. Oops I see I actually missed it, the reason was that this component didn't have any history. I had to go and make a few changes.

If Building A Component It Have History

Take it into account that if you are building a component from the ground up, it will have history. 00:07:33 This is only going to be happening when you have install a component via the import function in the components, or maybe using the demo component. I would advise open all the views and save them at least once, so that there is history recorded for that view. That is one of the drawbacks, there is really no way for me to my negate that issue. Since the history of each of these different items, being at the admin view and the fields needs to be created the moment that you saved the item. It can't be done before then. 00:08:14 Taking that an account, I'll recompile it again and fix that. It should increment it to 1.4.3. I will install that again. Going back refreshing the preacher, we will see that image field is back. Select an image. Click save and now you'll see that it does store the data for this image. 00:08:49 If we refresh the component, we will see that it is again incremented the version. If I open the update area, you will see that it added this new alter of the preacher table, adding the image field. It also added the new 00:09:16 version to this list. That is a quick demonstration of this new automated feature. It is in its very beta phase. We still going to be working on it to make sure that it's completely stable.

Please take a go at it if you find any bugs, look for other open issues, which someone already reported, and start commenting on that what you think should be done. If you don't find any, then please open an issue and let us fix this issue. 00:09:55 I think this will be a tremendous improvement to JCB, making it again with the one of the best Joomla component developing tools out there today. Where it is even writing your update SQL for you, being busy working and improving your component without being concerned about that.

Clone this wiki locally