/// <summary> /// Check if the specified column is a [PrimaryKey]. /// </summary> /// /// <param name="self">The Cassandra Fluent Migrator.</param> /// <param name="table">The Cassandra table name.</param> /// <param name="column">The Column to check.</param> /// <returns>True if Primary, False Otherwise.</returns> /// /// <exception cref="ApplicationException">Thrown when the Column is not a primary key.</exception> internal static bool IsPrimaryKey([NotNull] this ICassandraFluentMigrator self, [NotNull] string table, [NotNull] string column) { Check.NotNull(self, $"The argument [cassandra fluent migrator object]"); Check.NotEmptyNotNull(table, $"The argument [table]"); Check.NotEmptyNotNull(column, $"The argument [{nameof(column)}]"); var session = self.GetCassandraSession(); return(session .Cluster .Metadata .GetTable(session.Keyspace, table.NormalizeString()) .PartitionKeys .Any(x => x.Name.NormalizeString() == column.NormalizeString())); }
private static async Task <ICassandraFluentMigrator> ExecuteUdtStatementAsync([NotNull] this ICassandraFluentMigrator self, [NotNull] string query, [NotNull] string errorMessage = "throw error") { try { IStatement statement = new SimpleStatement(query); await self .GetCassandraSession() .ExecuteAsync(statement); } catch (Exception ex) { // Return the error if the message is other than the column exists. if (!ex.Message.NormalizeString().Contains(errorMessage.NormalizeString())) { throw ex; } } return(self); }
/// <summary> /// Build and execute the Reanme column query statement. /// </summary> /// /// <param name="self">The Cassandra Fluent Migrator.</param> /// <param name="table">The Cassandra table name.</param> /// <param name="column">Old Column to be renamed.</param> /// <param name="target">New Column name.</param> /// <returns>Cassandra Fluent Migrator.</returns> /// /// <exception cref="NullReferenceException">Thrown when the arguments are empty or null.</exception> internal static async Task <ICassandraFluentMigrator> ExecuteRenameColumnQueryAsync([NotNull] this ICassandraFluentMigrator self, [NotNull] string table, [NotNull] string column, [NotNull] string target) { Check.NotNull(self, $"The argument [cassandra fluent migrator object]"); Check.NotEmptyNotNull(table, $"The argument [table]"); Check.NotEmptyNotNull(column, $"The argument [old name]"); Check.NotEmptyNotNull(target, $"The argument [new name]"); var query = TableCqlStatements.TABLE_RENAME_COLUMN_STATEMENT.NormalizeString(table, column, target); return(await self.ExecuteStatementAsync(query, AppErrorsMessages.COLUMN_EXISTS_FOR_RENAME.NormalizeString(column, target, self.GetCassandraSession().Keyspace))); }