Check SQL DDL Files for Foreign-Key-References without Indexes

Hello,

we need SonarCube to check SQL files for certain constraints like “If you ALTER TABLE to create a new Foreign-Key REFERENCES Column, then you MUST also provide a proper CREATE INDEX statement for that as well”.
Those SQL files are checked in to the source-tree as schema-migrations and applied by Java-Flyway on deployments.

If my understanding is correct, SonarCube only supports PL/SQL and T/SQL? Is that correct or can we come up with rules for above SQL DDL Checks?

Thanks!

Hi,

Welcome to the community!

Natively we support T-SQL and PL/SQL starting in Developer Edition($). We also support the ability to write custom Java rules, and there’s also the possibility of writing a custom language plugin.

 
HTH,
Ann

Hey Ann,

what does this imply exactly?
I guess I cant use T-SQL/PL-SQL for those means?
What’s the recommended way to tackle this then, a custom language plugin?

Thanks,
Kai

Hi Kai,

Yes, you may need to write a custom plugin.

 
HTH,
Ann

Would we be able to use/integrate such a custom plugin in SonarCloud.io?

Oops. I overlooked the fact that you’re on SonarCloud. :woman_facepalming: Sorry about that.

So you would write the same analysis engine, but not in the form of a plugin. You’d run it before analysis to generate a Generic Issues report and pull that in as part of analysis.

 
Ann