Skip to content

Commit

Permalink
schema added optional column and index keywords
Browse files Browse the repository at this point in the history
For the MySQL schema grammar added:

 - optional column keyword for add, change, or modify alter operations
 - optional index keyword for fulltext and unique index alter operations
  • Loading branch information
silverqx committed Mar 15, 2023
1 parent 4cd5425 commit 5aa69c8
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 109 deletions.
11 changes: 6 additions & 5 deletions src/orm/schema/grammars/mysqlschemagrammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ QVector<QString> MySqlSchemaGrammar::compileAdd(const Blueprint &blueprint,
return {QStringLiteral("alter table %1 %2")
.arg(wrapTable(blueprint),
columnizeWithoutWrap(
prefixArray(Add, getColumns(blueprint))))};
prefixArray(QStringLiteral("add column"),
getColumns(blueprint))))};
}

QVector<QString> MySqlSchemaGrammar::compileChange(const Blueprint &blueprint,
Expand All @@ -123,8 +124,8 @@ QVector<QString> MySqlSchemaGrammar::compileChange(const Blueprint &blueprint,

columns << addModifiers(
QStringLiteral("%1 %2%3 %4")
.arg(isRenaming ? QStringLiteral("change")
: QStringLiteral("modify"),
.arg(isRenaming ? QStringLiteral("change column")
: QStringLiteral("modify column"),
wrap(column),
isRenaming ? QStringLiteral(" %1")
.arg(BaseGrammar::wrap(column.renameTo))
Expand Down Expand Up @@ -172,7 +173,7 @@ QVector<QString>
MySqlSchemaGrammar::compileUnique(const Blueprint &blueprint,
const IndexCommand &command) const
{
return {compileKey(blueprint, command, Unique)};
return {compileKey(blueprint, command, QStringLiteral("unique index"))};
}

QVector<QString>
Expand All @@ -186,7 +187,7 @@ QVector<QString>
MySqlSchemaGrammar::compileFullText(const Blueprint &blueprint,
const IndexCommand &command) const
{
return {compileKey(blueprint, command, Fulltext)};
return {compileKey(blueprint, command, QStringLiteral("fulltext index"))};
}

QVector<QString>
Expand Down
8 changes: 4 additions & 4 deletions tests/auto/unit/orm/schema/blueprint/tst_blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void tst_Blueprint::unsignedDecimal_WithTotalAndPlaces() const

QCOMPARE(blueprint.toSql(DB::connection(m_connection), MySqlSchemaGrammar()),
QVector<QString> {"alter table `cars` "
"add `money` decimal(10, 2) unsigned not null"});
"add column `money` decimal(10, 2) unsigned not null"});
}

void tst_Blueprint::removeColumn() const
Expand All @@ -284,7 +284,7 @@ void tst_Blueprint::removeColumn() const

QCOMPARE(blueprint.toSql(DB::connection(m_connection), MySqlSchemaGrammar()),
QVector<QString> {"alter table `torrents` "
"add `name` varchar(255) not null"});
"add column `name` varchar(255) not null"});
}

void tst_Blueprint::softDeletes() const
Expand All @@ -296,7 +296,7 @@ void tst_Blueprint::softDeletes() const

QCOMPARE(blueprint.toSql(DB::connection(m_connection), MySqlSchemaGrammar()),
QVector<QString> {"alter table `torrents` "
"add `deleted_at` timestamp null"});
"add column `deleted_at` timestamp null"});
}

void tst_Blueprint::softDeletes_Custom_ColumnName() const
Expand All @@ -308,7 +308,7 @@ void tst_Blueprint::softDeletes_Custom_ColumnName() const

QCOMPARE(blueprint.toSql(DB::connection(m_connection), MySqlSchemaGrammar()),
QVector<QString> {"alter table `torrents` "
"add `deleted_on` timestamp null"});
"add column `deleted_on` timestamp null"});
}

void tst_Blueprint::dropSoftDeletes() const
Expand Down
Loading

0 comments on commit 5aa69c8

Please sign in to comment.