<commit_before>component extends="wheels.tests.Test" {

	function setup() {
		migration = CreateObject("component", "wheels.migrator.Migration").init();
	}

	function test_addIndex_creates_an_index() {
		tableName = "dbm_addindex_tests";
		indexName = "idx_to_add";
		t = migration.createTable(name=tableName, force=true);
		t.integer(columnNames="integercolumn");
		t.create();

		migration.addIndex(table=tableName, columnName='integercolumn', indexName=indexName);
		info = $dbinfo(
			datasource=application.wheels.dataSourceName,
			table=tableName,
			type="index"
		);

		migration.dropTable(tableName);

		sql="SELECT * FROM query WHERE index_name = '#indexName#'";

		actual = $query(query=info, dbtype="query", sql=sql);
    assert("actual.recordCount eq 1");
		assert("actual.non_unique");
	}

	function test_add_index_on_mutiple_columns() {
		tableName = "dbm_addindex_tests";
		indexName = "idx_to_add_to_multiple_columns";
		t = migration.createTable(name=tableName, force=true);
		t.integer(columnNames="integercolumn,datecolumn");
		t.create();

		migration.addIndex(table=tableName, columnNames='integercolumn,datecolumn', indexName=indexName);
		info = $dbinfo(
			datasource=application.wheels.dataSourceName,
			table=tableName,
			type="index"
		);

		migration.dropTable(tableName);

		sql="SELECT * FROM query WHERE index_name = '#indexName#'";

		actual = $query(query=info, dbtype="query", sql=sql);
    	assert("actual.recordCount eq 2");
		assert("actual.non_unique");
	}

	// todo: unique index

	// default index name

}
<commit_msg>Make test for multiple columns in an index pass on CF 2018.<commit_after>component extends="wheels.tests.Test" {

	function setup() {
		migration = CreateObject("component", "wheels.migrator.Migration").init();
	}

	function test_addIndex_creates_an_index() {
		tableName = "dbm_addindex_tests";
		indexName = "idx_to_add";
		t = migration.createTable(name=tableName, force=true);
		t.integer(columnNames="integercolumn");
		t.create();

		migration.addIndex(table=tableName, columnName='integercolumn', indexName=indexName);
		info = $dbinfo(
			datasource=application.wheels.dataSourceName,
			table=tableName,
			type="index"
		);

		migration.dropTable(tableName);

		sql="SELECT * FROM query WHERE index_name = '#indexName#'";

		actual = $query(query=info, dbtype="query", sql=sql);
    assert("actual.recordCount eq 1");
		assert("actual.non_unique");
	}

	function test_add_index_on_mutiple_columns() {
		tableName = "dbm_addindex_tests";
		indexName = "idx_to_add_to_multiple_columns";
		t = migration.createTable(name=tableName, force=true);
		t.integer(columnNames="integercolumn,datecolumn");
		t.create();

		migration.addIndex(table=tableName, columnNames='integercolumn,datecolumn', indexName=indexName);
		info = $dbinfo(
			datasource=application.wheels.dataSourceName,
			table=tableName,
			type="index"
		);

		migration.dropTable(tableName);

		sql="SELECT * FROM query WHERE index_name = '#indexName#'";

		actual = $query(query=info, dbtype="query", sql=sql);

		// Added the ListLen check here for CF2018 because its cfdbinfo behaves a little differently.
		// It returns the index for multiple columns in one record where as Lucee returns multiple.
		assert("actual.recordCount eq 2 OR ListLen(actual['column_name'][1]) IS 2");
		assert("actual.non_unique");
	}

	// todo: unique index

	// default index name

}

{'fraction_non_alphanumeric': 0.13558823529411765, 'fraction_numerical': 0.00411764705882353, 'mean_word_length': 5.490458015267175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4730357', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1088, 'n_words': 206}