Skip to content

Commit

Permalink
Merge pull request #668 from and-voila/srizvi/issue666
Browse files Browse the repository at this point in the history
chore: misc. db optimizations #666
  • Loading branch information
srizvi authored Jan 25, 2024
2 parents 4facb9b + efc1af6 commit 777fef3
Show file tree
Hide file tree
Showing 26 changed files with 1,286 additions and 39 deletions.
2 changes: 1 addition & 1 deletion apps/ai/src/components/publish/blog-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function BlogCard({ data }: BlogCardProps) {
<Link href={`/${data.slug}`}>
<div className="ease overflow-hidden rounded-2xl border bg-card pb-6 shadow-md transition-all duration-200 hover:-translate-y-1 hover:shadow-xl">
<BlurImage
src={data.image!}
src={data.image ?? '/post-placeholder.jpg'}
alt={data.title ?? 'Blog Post'}
width={500}
height={400}
Expand Down
2 changes: 1 addition & 1 deletion apps/ai/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function withPostAuth(action: any) {
site: true,
},
});
if (!post || !post.site?.teamId) {
if (!post?.site?.teamId) {
return {
error: 'Post or site not found',
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { User } from '@prisma/client';
import type { Config } from 'unique-names-generator';

import { PrismaClient } from '@prisma/client';
Expand Down Expand Up @@ -247,7 +246,7 @@ export async function generateUniqueDisplayName(): Promise<string> {

while (!unique) {
newName = uniqueNamesGenerator(config);
const existingUser: User | null = await db.user.findFirst({
const existingUser = await db.user.findFirst({
where: { displayName: newName },
});

Expand Down
4 changes: 2 additions & 2 deletions apps/ai/src/lib/types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :: Authentication Module Types ::

import type { User as NextAuthUser } from 'next-auth';
import type { DefaultSession, User as NextAuthUser } from 'next-auth';

import 'next-auth/jwt';

Expand All @@ -21,6 +21,6 @@ declare module 'next-auth' {
interface Session {
user: User & {
id: UserId;
};
} & DefaultSession['user'];
}
}
2 changes: 1 addition & 1 deletion packages/db/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (!process.env.DREON_DIRECT_URL) {

export default {
schema: './src/schema',
out: './drizzle',
out: './src/migrations',
driver: 'pg',
dbCredentials: {
connectionString: process.env.DREON_DIRECT_URL,
Expand Down
62 changes: 31 additions & 31 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';

import * as accounts from './schema/accounts';
import * as adminRoleEnum from './schema/admin-role-enum';
import * as admins from './schema/admins';
import * as membershipRoleEnum from './schema/membership-role-enum';
import * as memberships from './schema/memberships';
import * as posts from './schema/posts';
import * as sessions from './schema/sessions';
import * as sites from './schema/sites';
import * as stripeCustomers from './schema/stripe-customers';
import * as stripeSubscriptionStatusEnum from './schema/stripe-subscription-status-enum';
import * as stripeSubscriptions from './schema/stripe-subscriptions';
import * as teamInvitations from './schema/team-invitations';
import * as teams from './schema/teams';
import * as users from './schema/users';
import * as verificationTokens from './schema/verification-tokens';
import * as accountsTable from './schema/accounts';
import * as adminRoleEnumTable from './schema/admin-role-enum';
import * as adminsTable from './schema/admins';
import * as membershipRoleEnumTable from './schema/membership-role-enum';
import * as membershipsTable from './schema/memberships';
import * as postsTable from './schema/posts';
import * as sessionsTable from './schema/sessions';
import * as sitesTable from './schema/sites';
import * as stripeCustomersTable from './schema/stripe-customers';
import * as stripeSubscriptionStatusEnumTable from './schema/stripe-subscription-status-enum';
import * as stripeSubscriptionsTable from './schema/stripe-subscriptions';
import * as teamInvitationsTable from './schema/team-invitations';
import * as teamsTable from './schema/teams';
import * as usersTable from './schema/users';
import * as verificationTokensTable from './schema/verification-tokens';

export const schema = {
...accounts,
...adminRoleEnum,
...admins,
...membershipRoleEnum,
...memberships,
...posts,
...sessions,
...sites,
...stripeCustomers,
...stripeSubscriptionStatusEnum,
...stripeSubscriptions,
...teamInvitations,
...teams,
...users,
...verificationTokens,
...accountsTable,
...adminRoleEnumTable,
...adminsTable,
...membershipRoleEnumTable,
...membershipsTable,
...postsTable,
...sessionsTable,
...sitesTable,
...stripeCustomersTable,
...stripeSubscriptionStatusEnumTable,
...stripeSubscriptionsTable,
...teamInvitationsTable,
...teamsTable,
...usersTable,
...verificationTokensTable,
};

export { myPgTable as tableCreator } from './schema/_table';

export * from './statements/statements';
export * from 'drizzle-orm';
export type { PgTableFn } from 'drizzle-orm/pg-core';

Expand Down
File renamed without changes.
71 changes: 71 additions & 0 deletions packages/db/src/migrations/0001_light_slapstick.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ALTER TABLE "av_accounts" DROP CONSTRAINT "av_accounts_userId_av_users_id_fk";
--> statement-breakpoint
ALTER TABLE "av_admins" DROP CONSTRAINT "av_admins_user_id_av_users_id_fk";
--> statement-breakpoint
ALTER TABLE "av_memberships" DROP CONSTRAINT "av_memberships_team_id_av_teams_id_fk";
--> statement-breakpoint
ALTER TABLE "av_posts" DROP CONSTRAINT "av_posts_user_id_av_users_id_fk";
--> statement-breakpoint
ALTER TABLE "av_sessions" DROP CONSTRAINT "av_sessions_userId_av_users_id_fk";
--> statement-breakpoint
ALTER TABLE "av_sites" DROP CONSTRAINT "av_sites_team_id_av_teams_id_fk";
--> statement-breakpoint
ALTER TABLE "av_stripe_customer" DROP CONSTRAINT "av_stripe_customer_user_id_av_users_id_fk";
--> statement-breakpoint
ALTER TABLE "av_stripe_subscriptions" DROP CONSTRAINT "av_stripe_subscriptions_team_id_av_teams_id_fk";
--> statement-breakpoint
ALTER TABLE "av_team_invitations" DROP CONSTRAINT "av_team_invitations_team_id_av_teams_id_fk";
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_accounts" ADD CONSTRAINT "av_accounts_userId_av_users_id_fk" FOREIGN KEY ("userId") REFERENCES "av_users"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_admins" ADD CONSTRAINT "av_admins_user_id_av_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "av_users"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_memberships" ADD CONSTRAINT "av_memberships_team_id_av_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "av_teams"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_posts" ADD CONSTRAINT "av_posts_user_id_av_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "av_users"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_sessions" ADD CONSTRAINT "av_sessions_userId_av_users_id_fk" FOREIGN KEY ("userId") REFERENCES "av_users"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_sites" ADD CONSTRAINT "av_sites_team_id_av_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "av_teams"("id") ON DELETE cascade ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_stripe_customer" ADD CONSTRAINT "av_stripe_customer_user_id_av_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "av_users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_stripe_subscriptions" ADD CONSTRAINT "av_stripe_subscriptions_team_id_av_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "av_teams"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "av_team_invitations" ADD CONSTRAINT "av_team_invitations_team_id_av_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "av_teams"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
File renamed without changes.
Loading

0 comments on commit 777fef3

Please sign in to comment.