Skip to content

Commit

Permalink
Add default value for hash column in User table
Browse files Browse the repository at this point in the history
  • Loading branch information
kcoderhtml committed May 2, 2024
1 parent 25eddab commit d83a78c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion db/config.ts
Original file line number Diff line number Diff line change
@@ -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 }),
Expand All @@ -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(),
Expand Down

0 comments on commit d83a78c

Please sign in to comment.