vania-dart / framework

Fast, simple, and powerful backend framework for Dart built with ❤️
https://vdart.dev
MIT License
155 stars 12 forks source link

[Feature Request] - Allow for column to be unique in migration #76

Closed PhillipMwaniki closed 1 month ago

PhillipMwaniki commented 1 month ago

Is your feature request related to a problem? Please describe. When designing some tables i.e. a users table, I do need the email column, and other columns, say phone_number to be unique.

The present documentation for migration doesn't have this. We also don't have this in the code as I have tried.

Describe the solution you'd like I would like it be

string('email').unique();

Describe alternatives you've considered Another school of thought is using of class attributes

string('email', unique: true);

Additional context

image
javad-zobeidi commented 1 month ago

This already exists

You can use index ex:

index(ColumnIndex.unique, 'email', ['email']);

Table code

 Future<void> up() async {
    super.up();
    await createTable('users', () {
      id();

      string('email');

      index(ColumnIndex.unique, 'email', ['email']);
    });
  }
PhillipMwaniki commented 1 month ago

Interesting. Thank you for the suggestion.