core: shorten Go referral codes for easier sharing

This commit is contained in:
vimtor
2026-05-17 00:37:39 +02:00
parent ee0c2cb33e
commit 6056a51656
5 changed files with 3080 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ const INVITE_COOKIE = "opencode.go.invite"
const INVITE_MAX_AGE = 60 * 60 * 24 * 30
export function normalizeInviteCode(code?: string | null) {
return code?.toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 16)
return code?.toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 10)
}
export function inviteCookie(code: string) {

View File

@@ -0,0 +1,2 @@
UPDATE `workspace` SET `referral_code` = NULL WHERE CHAR_LENGTH(`referral_code`) > 10;--> statement-breakpoint
ALTER TABLE `workspace` MODIFY COLUMN `referral_code` varchar(10);

View File

@@ -15,7 +15,7 @@ import { fn } from "./util/fn"
export namespace Referral {
export const REWARD_AMOUNT = centsToMicroCents(500)
const CODE_LENGTH = 16
const CODE_LENGTH = 10
function normalizeCode(code?: string) {
return code?.toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, CODE_LENGTH)

View File

@@ -6,7 +6,7 @@ export const WorkspaceTable = mysqlTable(
{
id: ulid("id").notNull().primaryKey(),
slug: varchar("slug", { length: 255 }),
referralCode: varchar("referral_code", { length: 16 }),
referralCode: varchar("referral_code", { length: 10 }),
name: varchar("name", { length: 255 }).notNull(),
...timestamps,
},