VVV icon indicating copy to clipboard operation
VVV copied to clipboard

Custom Site repo fails to create DB when the site name is an SQL reserved keyword

Open tomjn opened this issue 7 years ago • 4 comments

Expected Behavior

The site should provision if the site is named ssl

Current Behavior

The site half provisions, you get a WP install, but it fails to create the database for that site

Possible Solution

Prefixing the database name if it's found to be a reserved keyword. Prefixing all DB names would also work but this would break existing sites

Steps to Reproduce (for bugs)

Provision a site with the custom site template but name the site a reserved MySQL keyword, such as ssl

Your Environment

Latest VVV develop, macOS, VBox and Vagrant

tomjn avatar Apr 20 '17 14:04 tomjn

This works as a basic test, it just needs some extra steps:

  • move array to a separate file
  • add the other SQL reserved words
  • run some tests to verify
set -e
declare -A Sql_reserved
Sql_reserved[SSL]=1;
Sql_reserved[ACCESSIBLE]=1;
Sql_reserved[AFTER]=1;
Sql_reserved[BEGIN]=1;
Sql_reserved[BOOLEAN]=1;

dbname='moomins';
upper_case_db_name=`echo "${dbname}" | awk '{print toupper($0)}'`;

if [[ ${Sql_reserved[$upper_case_db_name]} ]]; then
	echo "${upper_case_db_name} is reserved";
else
	echo "passes"
fi

tomjn avatar Apr 27 '17 16:04 tomjn

This is a list of reserved words https://www.drupal.org/docs/develop/coding-standards/list-of-sql-reserved-words

I was thinking that we can add a tool that check if the name is reserved and in case add automatically a prefix like vvv. In this way all the usage of the db name in VVV can be moved to this script also in the various provisioners (to avoid duplicate code) and we have a unique tool that sanitize databases and also check if their exists and this kind of things.

Mte90 avatar May 08 '19 10:05 Mte90

This needs further testing, but I just tested provisioning a site named ssl and it worked.

Could have been fixed by my PR here https://github.com/Varying-Vagrant-Vagrants/custom-site-template/pull/18

msaggiorato avatar Oct 08 '19 20:10 msaggiorato

what about something more common like select or where?

tomjn avatar Oct 08 '19 23:10 tomjn