Advanced search in large datasets requires efficient indexes. Laravel allows adding full-text indexes, which are especially useful for search efficiency:
Schema::Table('Posts', function (blueprint $table) {
DB::Statement('ALTER TABLE posts ADD FULLTEXT fulltext_index(title, content)');
});
By adding a full-text index fulltext_indexto columns titlee content, searches for phrases in these columns will be significantly speeded up.
Setting default values using raw SQL
Using raw SQL queries in migrations enables the use of more advanced indonesia rcs data database functionality , such as setting default values via SQL functions:
Schema::Table('User', function (blueprint $table) {
DB::Statement("ALTER TABLE Users ADD COLUMN signup_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
});
In this case, by using CURRENT_TIMESTAMP, the sign_up_datenewly added column automatically gets the current date and time as the default value.
Adding a column with a unique UUID
UUIDs are a great way to ensure global uniqueness of records. Laravel makes it easy to add columns like this:
Schema::Table('Invoice', function (blueprint $table) {
$table->uuid('invoice_id')->unique();
});
Adding invoice_ida column with type UUID and setting it as unique provides strong uniqueness of the identifier in the database .
Adding full-text indexes
-
- Posts: 503
- Joined: Sun Dec 22, 2024 8:32 am