Gi
Gi
CCConvex Community
Created by Gi on 3/27/2025 in #general
seeding a project
Should I make a ticket for this somewhere? Would be useful in general to have a simple way to prune data older than x time
8 replies
CCConvex Community
Created by Gi on 3/27/2025 in #general
seeding a project
Hmm. I'd probably want to steer away from CLI "tricks" where possible. Will probably just create a helper mutation to clear the table like AITown's vacuum one
export const vacuumTable = internalMutation({
args: {
tableName: v.string(),
before: v.number(),
cursor: v.union(v.string(), v.null()),
soFar: v.number(),
},
handler: async (ctx, { tableName, before, cursor, soFar }) => {
const results = await ctx.db
.query(tableName as TableNames)
.withIndex('by_creation_time', (q) => q.lt('_creationTime', before))
.paginate({ cursor, numItems: DELETE_BATCH_SIZE });
for (const row of results.page) {
await ctx.db.delete(row._id);
}
if (!results.isDone) {
await ctx.scheduler.runAfter(0, internal.crons.vacuumTable, {
tableName,
before,
soFar: results.page.length + soFar,
cursor: results.continueCursor,
});
} else {
console.log(`Vacuumed ${soFar + results.page.length} entries from ${tableName}`);
}
},
}
export const vacuumTable = internalMutation({
args: {
tableName: v.string(),
before: v.number(),
cursor: v.union(v.string(), v.null()),
soFar: v.number(),
},
handler: async (ctx, { tableName, before, cursor, soFar }) => {
const results = await ctx.db
.query(tableName as TableNames)
.withIndex('by_creation_time', (q) => q.lt('_creationTime', before))
.paginate({ cursor, numItems: DELETE_BATCH_SIZE });
for (const row of results.page) {
await ctx.db.delete(row._id);
}
if (!results.isDone) {
await ctx.scheduler.runAfter(0, internal.crons.vacuumTable, {
tableName,
before,
soFar: results.page.length + soFar,
cursor: results.continueCursor,
});
} else {
console.log(`Vacuumed ${soFar + results.page.length} entries from ${tableName}`);
}
},
}
Would be a nice to have this on mutation/action ctx by default like ctx.db.clear(table) similar to the Clear Table button in dashboard
8 replies
CCConvex Community
Created by Gi on 3/27/2025 in #general
seeding a project
Nice, missed that one. Thanks!
8 replies
CCConvex Community
Created by Paul on 2/24/2025 in #support-community
How to have multiple schemas
Yup. All Convex functions in one package, and export the api/types to use in the other packages
14 replies
CCConvex Community
Created by ianpaschal on 2/23/2025 in #support-community
Convex Auth: How to add custom data to signIn() (or up)
something like this
import { defineSchema, defineTable } from "convex/server";
import { authTables } from "@convex-dev/auth/server";
import { v } from "convex/values";

const schema = defineSchema({
...authTables,
users: defineTable({
name: v.optional(v.string()),
image: v.optional(v.string()),
email: v.optional(v.string()),
emailVerificationTime: v.optional(v.number()),
phone: v.optional(v.string()),
phoneVerificationTime: v.optional(v.number()),
isAnonymous: v.optional(v.boolean()),
// other "users" fields...
roles: v.optional(v.array(v.string()))
}).index("email", ["email"]),
// Your other tables...
});

export default schema;
import { defineSchema, defineTable } from "convex/server";
import { authTables } from "@convex-dev/auth/server";
import { v } from "convex/values";

const schema = defineSchema({
...authTables,
users: defineTable({
name: v.optional(v.string()),
image: v.optional(v.string()),
email: v.optional(v.string()),
emailVerificationTime: v.optional(v.number()),
phone: v.optional(v.string()),
phoneVerificationTime: v.optional(v.number()),
isAnonymous: v.optional(v.boolean()),
// other "users" fields...
roles: v.optional(v.array(v.string()))
}).index("email", ["email"]),
// Your other tables...
});

export default schema;
31 replies
CCConvex Community
Created by ianpaschal on 2/23/2025 in #support-community
Convex Auth: How to add custom data to signIn() (or up)
And that table is called "users" right?
31 replies
CCConvex Community
Created by ianpaschal on 2/23/2025 in #support-community
Convex Auth: How to add custom data to signIn() (or up)
the custom ones
31 replies
CCConvex Community
Created by ianpaschal on 2/23/2025 in #support-community
Convex Auth: How to add custom data to signIn() (or up)
the fields have values?
31 replies