Moved birthdate into separate table.
This commit is contained in:
parent
2c4d35e2dd
commit
c28e0a90dd
12 changed files with 225 additions and 94 deletions
40
database/2025_02_08_013647_create_user_birthdates_table.php
Normal file
40
database/2025_02_08_013647_create_user_birthdates_table.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\DbMigration;
|
||||
|
||||
final class CreateUserBirthdatesTable_20250208_013647 implements DbMigration {
|
||||
public function migrate(DbConnection $conn): void {
|
||||
$conn->execute(<<<SQL
|
||||
CREATE TABLE msz_users_birthdates (
|
||||
user_id INT(10) UNSIGNED NOT NULL,
|
||||
birth_year SMALLINT(6) NULL DEFAULT NULL,
|
||||
birth_month TINYINT(3) UNSIGNED NOT NULL,
|
||||
birth_day TINYINT(3) UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (user_id),
|
||||
INDEX users_birthdates_index (birth_month, birth_day),
|
||||
CONSTRAINT users_birthdates_users_foreign
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES msz_users (user_id)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE CASCADE,
|
||||
CONSTRAINT users_birthdates_ensure_month
|
||||
CHECK (birth_month BETWEEN 1 AND 12),
|
||||
CONSTRAINT users_birthdates_ensure_day
|
||||
CHECK (birth_day BETWEEN 1 AND 31)
|
||||
) ENGINE=InnoDB COLLATE='utf8mb4_bin';
|
||||
SQL);
|
||||
|
||||
$conn->execute(<<<SQL
|
||||
INSERT INTO msz_users_birthdates
|
||||
SELECT user_id, IF(YEAR(user_birthdate) <= 1004, NULL, YEAR(user_birthdate)), MONTH(user_birthdate), DAY(user_birthdate)
|
||||
FROM msz_users
|
||||
WHERE user_birthdate IS NOT NULL
|
||||
SQL);
|
||||
|
||||
$conn->execute(<<<SQL
|
||||
ALTER TABLE msz_users
|
||||
DROP COLUMN user_birthdate,
|
||||
DROP INDEX users_birthdate_index;
|
||||
SQL);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue