refactor: make casing for column names consistent (#1517)
* refactor: make casing for column names consistent * fix: format issues
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
ALTER TABLE `account` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
|
||||
ALTER TABLE `account` RENAME COLUMN `providerAccountId` TO `provider_account_id`;--> statement-breakpoint
|
||||
ALTER TABLE `apiKey` RENAME COLUMN `apiKey` TO `api_key`;--> statement-breakpoint
|
||||
ALTER TABLE `apiKey` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` RENAME COLUMN `groupId` TO `group_id`;--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
|
||||
ALTER TABLE `groupPermission` RENAME COLUMN `groupId` TO `group_id`;--> statement-breakpoint
|
||||
ALTER TABLE `iconRepository` RENAME COLUMN `iconRepository_id` TO `id`;--> statement-breakpoint
|
||||
ALTER TABLE `iconRepository` RENAME COLUMN `iconRepository_slug` TO `slug`;--> statement-breakpoint
|
||||
ALTER TABLE `icon` RENAME COLUMN `icon_id` TO `id`;--> statement-breakpoint
|
||||
ALTER TABLE `icon` RENAME COLUMN `icon_name` TO `name`;--> statement-breakpoint
|
||||
ALTER TABLE `icon` RENAME COLUMN `icon_url` TO `url`;--> statement-breakpoint
|
||||
ALTER TABLE `icon` RENAME COLUMN `icon_checksum` TO `checksum`;--> statement-breakpoint
|
||||
ALTER TABLE `icon` RENAME COLUMN `iconRepository_id` TO `icon_repository_id`;--> statement-breakpoint
|
||||
ALTER TABLE `serverSetting` RENAME COLUMN `key` TO `setting_key`;--> statement-breakpoint
|
||||
ALTER TABLE `session` RENAME COLUMN `sessionToken` TO `session_token`;--> statement-breakpoint
|
||||
ALTER TABLE `session` RENAME COLUMN `userId` TO `user_id`;--> statement-breakpoint
|
||||
ALTER TABLE `user` RENAME COLUMN `emailVerified` TO `email_verified`;--> statement-breakpoint
|
||||
ALTER TABLE `user` RENAME COLUMN `homeBoardId` TO `home_board_id`;--> statement-breakpoint
|
||||
ALTER TABLE `user` RENAME COLUMN `colorScheme` TO `color_scheme`;--> statement-breakpoint
|
||||
ALTER TABLE `user` RENAME COLUMN `firstDayOfWeek` TO `first_day_of_week`;--> statement-breakpoint
|
||||
ALTER TABLE `user` RENAME COLUMN `pingIconsEnabled` TO `ping_icons_enabled`;--> statement-breakpoint
|
||||
ALTER TABLE `serverSetting` DROP INDEX `serverSetting_key_unique`;--> statement-breakpoint
|
||||
ALTER TABLE `account` DROP FOREIGN KEY `account_userId_user_id_fk`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `apiKey` DROP FOREIGN KEY `apiKey_userId_user_id_fk`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` DROP FOREIGN KEY `groupMember_groupId_group_id_fk`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` DROP FOREIGN KEY `groupMember_userId_user_id_fk`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `groupPermission` DROP FOREIGN KEY `groupPermission_groupId_group_id_fk`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `icon` DROP FOREIGN KEY `icon_iconRepository_id_iconRepository_iconRepository_id_fk`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `session` DROP FOREIGN KEY `session_userId_user_id_fk`;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `user` DROP FOREIGN KEY `user_homeBoardId_board_id_fk`;
|
||||
--> statement-breakpoint
|
||||
DROP INDEX `userId_idx` ON `account`;--> statement-breakpoint
|
||||
DROP INDEX `user_id_idx` ON `session`;--> statement-breakpoint
|
||||
ALTER TABLE `account` DROP PRIMARY KEY;--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` DROP PRIMARY KEY;--> statement-breakpoint
|
||||
ALTER TABLE `iconRepository` DROP PRIMARY KEY;--> statement-breakpoint
|
||||
ALTER TABLE `icon` DROP PRIMARY KEY;--> statement-breakpoint
|
||||
ALTER TABLE `serverSetting` DROP PRIMARY KEY;--> statement-breakpoint
|
||||
ALTER TABLE `session` DROP PRIMARY KEY;--> statement-breakpoint
|
||||
ALTER TABLE `account` ADD PRIMARY KEY(`provider`,`provider_account_id`);--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` ADD PRIMARY KEY(`group_id`,`user_id`);--> statement-breakpoint
|
||||
ALTER TABLE `iconRepository` ADD PRIMARY KEY(`id`);--> statement-breakpoint
|
||||
ALTER TABLE `icon` ADD PRIMARY KEY(`id`);--> statement-breakpoint
|
||||
ALTER TABLE `serverSetting` ADD PRIMARY KEY(`setting_key`);--> statement-breakpoint
|
||||
ALTER TABLE `session` ADD PRIMARY KEY(`session_token`);--> statement-breakpoint
|
||||
ALTER TABLE `serverSetting` ADD CONSTRAINT `serverSetting_settingKey_unique` UNIQUE(`setting_key`);--> statement-breakpoint
|
||||
ALTER TABLE `account` ADD CONSTRAINT `account_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `apiKey` ADD CONSTRAINT `apiKey_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_group_id_group_id_fk` FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `groupMember` ADD CONSTRAINT `groupMember_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `groupPermission` ADD CONSTRAINT `groupPermission_group_id_group_id_fk` FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `icon` ADD CONSTRAINT `icon_icon_repository_id_iconRepository_id_fk` FOREIGN KEY (`icon_repository_id`) REFERENCES `iconRepository`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `session` ADD CONSTRAINT `session_user_id_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE `user` ADD CONSTRAINT `user_home_board_id_board_id_fk` FOREIGN KEY (`home_board_id`) REFERENCES `board`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX `userId_idx` ON `account` (`user_id`);--> statement-breakpoint
|
||||
CREATE INDEX `user_id_idx` ON `session` (`user_id`);
|
||||
1650
packages/db/migrations/mysql/meta/0016_snapshot.json
Normal file
1650
packages/db/migrations/mysql/meta/0016_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -113,6 +113,13 @@
|
||||
"when": 1730653393442,
|
||||
"tag": "0015_unknown_firedrake",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 16,
|
||||
"version": "5",
|
||||
"when": 1732212709518,
|
||||
"tag": "0016_change_all_to_snake_case",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ const migrateAsync = async () => {
|
||||
const db = drizzle(mysql2, {
|
||||
mode: "default",
|
||||
schema: mysqlSchema,
|
||||
casing: "snake_case",
|
||||
});
|
||||
|
||||
await migrate(db, { migrationsFolder });
|
||||
|
||||
102
packages/db/migrations/sqlite/0016_change_all_to_snake_case.sql
Normal file
102
packages/db/migrations/sqlite/0016_change_all_to_snake_case.sql
Normal file
@@ -0,0 +1,102 @@
|
||||
ALTER TABLE `iconRepository` RENAME COLUMN "iconRepository_id" TO "id";--> statement-breakpoint
|
||||
ALTER TABLE `iconRepository` RENAME COLUMN "iconRepository_slug" TO "slug";--> statement-breakpoint
|
||||
ALTER TABLE `serverSetting` RENAME COLUMN "key" TO "setting_key";--> statement-breakpoint
|
||||
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
||||
CREATE TABLE `__new_account` (
|
||||
`user_id` text NOT NULL,
|
||||
`type` text NOT NULL,
|
||||
`provider` text NOT NULL,
|
||||
`provider_account_id` text NOT NULL,
|
||||
`refresh_token` text,
|
||||
`access_token` text,
|
||||
`expires_at` integer,
|
||||
`token_type` text,
|
||||
`scope` text,
|
||||
`id_token` text,
|
||||
`session_state` text,
|
||||
PRIMARY KEY(`provider`, `provider_account_id`),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_account`("user_id", "type", "provider", "provider_account_id", "refresh_token", "access_token", "expires_at", "token_type", "scope", "id_token", "session_state") SELECT "userId", "type", "provider", "providerAccountId", "refresh_token", "access_token", "expires_at", "token_type", "scope", "id_token", "session_state" FROM `account`;--> statement-breakpoint
|
||||
DROP TABLE `account`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_account` RENAME TO `account`;--> statement-breakpoint
|
||||
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
||||
CREATE INDEX `userId_idx` ON `account` (`user_id`);--> statement-breakpoint
|
||||
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
||||
CREATE TABLE `__new_apiKey` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`api_key` text NOT NULL,
|
||||
`salt` text NOT NULL,
|
||||
`user_id` text NOT NULL,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_apiKey`("id", "api_key", "salt", "user_id") SELECT "id", "apiKey", "salt", "userId" FROM `apiKey`;--> statement-breakpoint
|
||||
DROP TABLE `apiKey`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_apiKey` RENAME TO `apiKey`;--> statement-breakpoint
|
||||
CREATE TABLE `__new_groupMember` (
|
||||
`group_id` text NOT NULL,
|
||||
`user_id` text NOT NULL,
|
||||
PRIMARY KEY(`group_id`, `user_id`),
|
||||
FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_groupMember`("group_id", "user_id") SELECT "groupId", "userId" FROM `groupMember`;--> statement-breakpoint
|
||||
DROP TABLE `groupMember`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_groupMember` RENAME TO `groupMember`;--> statement-breakpoint
|
||||
CREATE TABLE `__new_groupPermission` (
|
||||
`group_id` text NOT NULL,
|
||||
`permission` text NOT NULL,
|
||||
FOREIGN KEY (`group_id`) REFERENCES `group`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_groupPermission`("group_id", "permission") SELECT "groupId", "permission" FROM `groupPermission`;--> statement-breakpoint
|
||||
DROP TABLE `groupPermission`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_groupPermission` RENAME TO `groupPermission`;--> statement-breakpoint
|
||||
CREATE TABLE `__new_icon` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`url` text NOT NULL,
|
||||
`checksum` text NOT NULL,
|
||||
`icon_repository_id` text NOT NULL,
|
||||
FOREIGN KEY (`icon_repository_id`) REFERENCES `iconRepository`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_icon`("id", "name", "url", "checksum", "icon_repository_id") SELECT "icon_id", "icon_name", "icon_url", "icon_checksum", "iconRepository_id" FROM `icon`;--> statement-breakpoint
|
||||
DROP TABLE `icon`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_icon` RENAME TO `icon`;--> statement-breakpoint
|
||||
DROP INDEX IF EXISTS `serverSetting_key_unique`;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `serverSetting_settingKey_unique` ON `serverSetting` (`setting_key`);--> statement-breakpoint
|
||||
CREATE TABLE `__new_session` (
|
||||
`session_token` text PRIMARY KEY NOT NULL,
|
||||
`user_id` text NOT NULL,
|
||||
`expires` integer NOT NULL,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_session`("session_token", "user_id", "expires") SELECT "sessionToken", "userId", "expires" FROM `session`;--> statement-breakpoint
|
||||
DROP TABLE `session`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_session` RENAME TO `session`;--> statement-breakpoint
|
||||
CREATE INDEX `user_id_idx` ON `session` (`user_id`);--> statement-breakpoint
|
||||
CREATE TABLE `__new_user` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`name` text,
|
||||
`email` text,
|
||||
`email_verified` integer,
|
||||
`image` text,
|
||||
`password` text,
|
||||
`salt` text,
|
||||
`provider` text DEFAULT 'credentials' NOT NULL,
|
||||
`home_board_id` text,
|
||||
`color_scheme` text DEFAULT 'dark' NOT NULL,
|
||||
`first_day_of_week` integer DEFAULT 1 NOT NULL,
|
||||
`ping_icons_enabled` integer DEFAULT false NOT NULL,
|
||||
FOREIGN KEY (`home_board_id`) REFERENCES `board`(`id`) ON UPDATE no action ON DELETE set null
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_user`("id", "name", "email", "email_verified", "image", "password", "salt", "provider", "home_board_id", "color_scheme", "first_day_of_week", "ping_icons_enabled") SELECT "id", "name", "email", "emailVerified", "image", "password", "salt", "provider", "homeBoardId", "colorScheme", "firstDayOfWeek", "pingIconsEnabled" FROM `user`;--> statement-breakpoint
|
||||
DROP TABLE `user`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_user` RENAME TO `user`;--> statement-breakpoint
|
||||
PRAGMA foreign_keys=ON;
|
||||
1579
packages/db/migrations/sqlite/meta/0016_snapshot.json
Normal file
1579
packages/db/migrations/sqlite/meta/0016_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -113,6 +113,13 @@
|
||||
"when": 1730653336134,
|
||||
"tag": "0015_superb_psylocke",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 16,
|
||||
"version": "6",
|
||||
"when": 1732210918783,
|
||||
"tag": "0016_change_all_to_snake_case",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ const migrationsFolder = process.argv[2] ?? ".";
|
||||
const migrateAsync = async () => {
|
||||
const sqlite = new Database(process.env.DB_URL?.replace("file:", ""));
|
||||
|
||||
const db = drizzle(sqlite, { schema });
|
||||
const db = drizzle(sqlite, { schema, casing: "snake_case" });
|
||||
|
||||
migrate(db, { migrationsFolder });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user