<commit_before>extension SchemaSupporting where SchemaAction: FluentSQLSchemaStatement {
    /// See `SchemaSupporting`.
    public static var schemaActionCreate: SchemaAction {
        return .createTable
    }
    
    /// See `SchemaSupporting`.
    public static var schemaActionUpdate: SchemaAction {
        return .alterTable
    }
    
    /// See `SchemaSupporting`.
    public static var schemaActionDelete: SchemaAction {
        return .dropTable
    }
}

extension SchemaSupporting where Schema: FluentSQLSchema, SchemaAction == Schema.Statement {
    /// See `SchemaSupporting`.
    public static func schemaCreate(_ action: SchemaAction, _ entity: String) -> Schema {
        return .schema(action, .table(.identifier(entity)))
    }
}

extension SchemaSupporting where
    SchemaField: SQLColumnDefinition,
    SchemaFieldType == SchemaField.DataType,
    QueryField == SchemaField.ColumnIdentifier
{
    /// See `SchemaSupporting`.
    public static func schemaField(_ field: QueryField, _ type: SchemaFieldType) -> SchemaField {
        return .columnDefinition(field, type, [])
    }
}

extension SchemaSupporting where Schema: FluentSQLSchema, SchemaField == Schema.ColumnDefinition {
    /// See `SchemaSupporting`.
    public static func schemaFieldCreate(_ field: SchemaField, to query: inout Schema) {
        query.columns.append(field)
    }
}

extension SchemaSupporting where Schema: FluentSQLSchema, QueryField == Schema.ColumnIdentifier {
    /// See `SchemaSupporting`.
    public static func schemaFieldDelete(_ field: QueryField, to query: inout Schema) {
        query.deleteColumns.append(field)
    }
}


extension SchemaSupporting where Schema: FluentSQLSchema, SchemaConstraint == Schema.TableConstraint {
    /// See `SchemaSupporting`.
    public static func schemaConstraintCreate(_ constraint: SchemaConstraint, to query: inout Schema) {
        query.constraints.append(constraint)
    }
    
    /// See `SchemaSupporting`.
    public static func schemaConstraintDelete(_ constraint: SchemaConstraint, to query: inout Schema) {
        query.deleteConstraints.append(constraint)
    }
}

public protocol SQLConstraintIdentifierNormalizer {
    static func normalizeSQLConstraintIdentifier(_ identifier: String) -> String
}

extension SchemaSupporting where
    SchemaConstraint: SQLTableConstraint,
    QueryField: SQLColumnIdentifier,
    QueryField.Identifier == SchemaConstraint.Algorithm.Identifier,
    SchemaReferenceAction == SchemaConstraint.Algorithm.ForeignKey.ConflictResolution,
    QueryField.TableIdentifier == SchemaConstraint.Algorithm.ForeignKey.TableIdentifier,
    QueryField.Identifier == SchemaConstraint.Algorithm.ForeignKey.Identifier,
    Self: SQLConstraintIdentifierNormalizer
{
    /// See `SchemaSupporting`.
    public static func schemaReference(from: QueryField, to: QueryField, onUpdate: SchemaReferenceAction?, onDelete: SchemaReferenceAction?) -> SchemaConstraint {
        guard let foreignTable = to.table else {
            fatalError("Cannot create reference to column without table identifier: \(to).")
        }
        guard let localTable = from.table else {
            fatalError("Cannot create reference from column without table identifier: \(from).")
        }
        let uid = "\(localTable.identifier.string).\(from.identifier.string)+\(foreignTable.identifier.string).\(to.identifier.string)"
        return .constraint(
            .foreignKey([from.identifier], .foreignKey(foreignTable, [to.identifier], onDelete: onDelete, onUpdate: onUpdate)),
            .identifier("fk:\(normalizeSQLConstraintIdentifier(uid))")
        )
    }
}

extension SchemaSupporting where
    SchemaConstraint: SQLTableConstraint,
    QueryField: SQLColumnIdentifier,
    QueryField.Identifier == SchemaConstraint.Algorithm.Identifier,
    Self: SQLConstraintIdentifierNormalizer
{
    /// See `SchemaSupporting`.
    public static func schemaUnique(on: [QueryField]) -> SchemaConstraint {
        let uid = on.map { $0.identifier.string }.joined(separator: "+")
        return .constraint(.unique(on.map { $0.identifier }), .identifier("uq:\(normalizeSQLConstraintIdentifier(uid))"))
    }
}

extension SchemaSupporting {
    
}<commit_msg>unique constraint name fix<commit_after>extension SchemaSupporting where SchemaAction: FluentSQLSchemaStatement {
    /// See `SchemaSupporting`.
    public static var schemaActionCreate: SchemaAction {
        return .createTable
    }
    
    /// See `SchemaSupporting`.
    public static var schemaActionUpdate: SchemaAction {
        return .alterTable
    }
    
    /// See `SchemaSupporting`.
    public static var schemaActionDelete: SchemaAction {
        return .dropTable
    }
}

extension SchemaSupporting where Schema: FluentSQLSchema, SchemaAction == Schema.Statement {
    /// See `SchemaSupporting`.
    public static func schemaCreate(_ action: SchemaAction, _ entity: String) -> Schema {
        return .schema(action, .table(.identifier(entity)))
    }
}

extension SchemaSupporting where
    SchemaField: SQLColumnDefinition,
    SchemaFieldType == SchemaField.DataType,
    QueryField == SchemaField.ColumnIdentifier
{
    /// See `SchemaSupporting`.
    public static func schemaField(_ field: QueryField, _ type: SchemaFieldType) -> SchemaField {
        return .columnDefinition(field, type, [])
    }
}

extension SchemaSupporting where Schema: FluentSQLSchema, SchemaField == Schema.ColumnDefinition {
    /// See `SchemaSupporting`.
    public static func schemaFieldCreate(_ field: SchemaField, to query: inout Schema) {
        query.columns.append(field)
    }
}

extension SchemaSupporting where Schema: FluentSQLSchema, QueryField == Schema.ColumnIdentifier {
    /// See `SchemaSupporting`.
    public static func schemaFieldDelete(_ field: QueryField, to query: inout Schema) {
        query.deleteColumns.append(field)
    }
}


extension SchemaSupporting where Schema: FluentSQLSchema, SchemaConstraint == Schema.TableConstraint {
    /// See `SchemaSupporting`.
    public static func schemaConstraintCreate(_ constraint: SchemaConstraint, to query: inout Schema) {
        query.constraints.append(constraint)
    }
    
    /// See `SchemaSupporting`.
    public static func schemaConstraintDelete(_ constraint: SchemaConstraint, to query: inout Schema) {
        query.deleteConstraints.append(constraint)
    }
}

public protocol SQLConstraintIdentifierNormalizer {
    static func normalizeSQLConstraintIdentifier(_ identifier: String) -> String
}

extension SchemaSupporting where
    SchemaConstraint: SQLTableConstraint,
    QueryField: SQLColumnIdentifier,
    QueryField.Identifier == SchemaConstraint.Algorithm.Identifier,
    SchemaReferenceAction == SchemaConstraint.Algorithm.ForeignKey.ConflictResolution,
    QueryField.TableIdentifier == SchemaConstraint.Algorithm.ForeignKey.TableIdentifier,
    QueryField.Identifier == SchemaConstraint.Algorithm.ForeignKey.Identifier,
    Self: SQLConstraintIdentifierNormalizer
{
    /// See `SchemaSupporting`.
    public static func schemaReference(from: QueryField, to: QueryField, onUpdate: SchemaReferenceAction?, onDelete: SchemaReferenceAction?) -> SchemaConstraint {
        guard let foreignTable = to.table else {
            fatalError("Cannot create reference to column without table identifier: \(to).")
        }
        guard let localTable = from.table else {
            fatalError("Cannot create reference from column without table identifier: \(from).")
        }
        let uid = "\(localTable.identifier.string).\(from.identifier.string)+\(foreignTable.identifier.string).\(to.identifier.string)"
        return .constraint(
            .foreignKey([from.identifier], .foreignKey(foreignTable, [to.identifier], onDelete: onDelete, onUpdate: onUpdate)),
            .identifier("fk:\(normalizeSQLConstraintIdentifier(uid))")
        )
    }
}

extension SchemaSupporting where
    SchemaConstraint: SQLTableConstraint,
    QueryField: SQLColumnIdentifier,
    QueryField.Identifier == SchemaConstraint.Algorithm.Identifier,
    Self: SQLConstraintIdentifierNormalizer
{
    /// See `SchemaSupporting`.
    public static func schemaUnique(on: [QueryField]) -> SchemaConstraint {
        let uid = on.map {
            guard let table = $0.table else {
                fatalError("Cannot create unique constraint on column without table identifier: \($0).")
            }
            return "\(table.identifier.string).\($0.identifier.string)"
        }.joined(separator: "+")
        return .constraint(.unique(on.map { $0.identifier }), .identifier("uq:\(normalizeSQLConstraintIdentifier(uid))"))
    }
}

extension SchemaSupporting {
    
}
{'fraction_non_alphanumeric': 0.09590778097982709, 'fraction_numerical': 0.00069164265129683, 'mean_word_length': 3.677088948787062, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5206812', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2066, 'n_words': 539}