From d83a78c72a8b0f259dc77d5ae2c9b9bfb0edf8e9 Mon Sep 17 00:00:00 2001 From: Kieran Klukas <92754843+kcoderhtml@users.noreply.github.com> Date: Thu, 2 May 2024 12:02:42 -0400 Subject: [PATCH] Add default value for hash column in User table --- db/config.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/db/config.ts b/db/config.ts index d5c4328..282d7c3 100644 --- a/db/config.ts +++ b/db/config.ts @@ -1,5 +1,16 @@ import { defineDb, defineTable, column } from "astro:db"; +function generateRandomString() { + const chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < 16; i++) { + const randomIndex = Math.floor(Math.random() * chars.length); + result += chars.charAt(randomIndex); + } + return result; +} + const Organization = defineTable({ columns: { team: column.text({ primaryKey: true }), @@ -15,7 +26,7 @@ const Organization = defineTable({ const User = defineTable({ columns: { userId: column.text({ primaryKey: true }), - hash: column.text(), + hash: column.text({ default: generateRandomString() }), team: column.text(), name: column.text(), email: column.text(),