The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: Pro+ users can choose compute size during project creation (#21292)
Ivan Vasilovd07a820440ff
diff --git a/apps/studio/data/api.d.ts b/apps/studio/data/api.d.tsindex d3c8fd3a7e3..e37a869108f 100644--- a/apps/studio/data/api.d.ts+++ b/apps/studio/data/api.d.ts@@ -1457,9 +1457,9 @@ export interface paths {* List all projects* @description Returns a list of all projects you've previously created.*/- get: operations['ProjectsController_getProjects']+ get: operations['V1ProjectsController_getProjects']/** Create a project */- post: operations['ProjectsController_createProject']+ post: operations['V1ProjectsController_createProject']}'/v1/projects/{ref}/api-keys': {/** Get project api keys */@@ -3412,6 +3412,18 @@ export interface components {GetProjectByFlyExtensionIdResponse: {ref: string}+ /** @enum {string} */+ DesiredInstanceSize:+ | 'micro'+ | 'small'+ | 'medium'+ | 'large'+ | 'xlarge'+ | '2xlarge'+ | '4xlarge'+ | '8xlarge'+ | '12xlarge'+ | '16xlarge'AmiSearchOptions: {search_tags?: Record<string, never>}@@ -3421,16 +3433,17 @@ export interface components {CreateProjectBody: {/** @deprecated */kps_enabled?: boolean+ desired_instance_size?: components['schemas']['DesiredInstanceSize']cloud_provider: stringorg_id: numbername: stringdb_pass: stringdb_region: string- db_pricing_tier_id: string+ db_pricing_tier_id?: stringdb_sql?: stringauth_site_url?: stringvercel_configuration_id?: string- custom_supabase_internal_requests: components['schemas']['CustomSupabaseInternalRequests']+ custom_supabase_internal_requests?: components['schemas']['CustomSupabaseInternalRequests']}CreateProjectResponse: {infra_compute_size?: components['schemas']['DbInstanceSize']@@ -8793,29 +8806,29 @@ export interface operations {}}/**- * List all projects- * @description Returns a list of all projects you've previously created.+ * Gets all projects that belong to the authenticated user+ * @description Only returns the minimal project info*/ProjectsController_getProjects: {responses: {200: {content: {- 'application/json': components['schemas']['V1ProjectResponse'][]+ 'application/json': components['schemas']['ProjectInfo'][]}}}}- /** Create a project */+ /** Creates a project */ProjectsController_createProject: {requestBody: {content: {- 'application/json': components['schemas']['V1CreateProjectBody']+ 'application/json': components['schemas']['CreateProjectBody']}}responses: {201: {content: {- 'application/json': components['schemas']['V1ProjectResponse']+ 'application/json': components['schemas']['CreateProjectResponse']}}}@@ -11728,6 +11741,34 @@ export interface operations {}}}+ /**+ * List all projects+ * @description Returns a list of all projects you've previously created.+ */+ V1ProjectsController_getProjects: {+ responses: {+ 200: {+ content: {+ 'application/json': components['schemas']['V1ProjectResponse'][]+ }+ }+ }+ }+ /** Create a project */+ V1ProjectsController_createProject: {+ requestBody: {+ content: {+ 'application/json': components['schemas']['V1CreateProjectBody']+ }+ }+ responses: {+ 201: {+ content: {+ 'application/json': components['schemas']['V1ProjectResponse']+ }+ }+ }+ }/** Get project api keys */ApiKeysController_getProjectApiKeys: {parameters: {diff --git a/apps/studio/data/projects/project-create-mutation.ts b/apps/studio/data/projects/project-create-mutation.tsindex 6fa51da915c..411de893df8 100644--- a/apps/studio/data/projects/project-create-mutation.ts+++ b/apps/studio/data/projects/project-create-mutation.ts@@ -1,11 +1,14 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'lib/common/fetch'-import { API_URL, PRICING_TIER_PRODUCT_IDS, PROVIDERS } from 'lib/constants'-import { ProjectBase, ResponseError } from 'types'+import { components } from 'data/api'+import { post } from 'data/fetchers'+import { PRICING_TIER_PRODUCT_IDS, PROVIDERS } from 'lib/constants'+import { ResponseError } from 'types'import { projectKeys } from './keys'+export type DbInstanceSize = components['schemas']['DesiredInstanceSize']+export type ProjectCreateVariables = {name: stringorganizationId: number@@ -17,6 +20,7 @@ export type ProjectCreateVariables = {configurationId?: stringauthSiteUrl?: stringcustomSupabaseRequest?: object+ dbInstanceSize?: DbInstanceSize}export async function createProject({@@ -25,28 +29,33 @@ export async function createProject({dbPass,dbRegion,dbSql,- dbPricingTierId = PRICING_TIER_PRODUCT_IDS.FREE,cloudProvider = PROVIDERS.AWS.id,configurationId,authSiteUrl,customSupabaseRequest,+ dbInstanceSize,}: ProjectCreateVariables) {- const response = await post(`${API_URL}/projects`, {+ const body: components['schemas']['CreateProjectBody'] = {cloud_provider: cloudProvider,org_id: organizationId,name,db_pass: dbPass,db_region: dbRegion,db_sql: dbSql,- db_pricing_tier_id: dbPricingTierId,auth_site_url: authSiteUrl,vercel_configuration_id: configurationId,...(customSupabaseRequest !== undefined && {- custom_supabase_internal_requests: customSupabaseRequest,+ custom_supabase_internal_requests: customSupabaseRequest as any,}),+ desired_instance_size: dbInstanceSize,+ }++ const { data, error } = await post(`/platform/projects`, {+ body,})- if (response.error) throw response.error- return response as ProjectBase++ if (error) throw error+ return data}type ProjectCreateData = Awaited<ReturnType<typeof createProject>>diff --git a/apps/studio/data/projects/projects-query.ts b/apps/studio/data/projects/projects-query.tsindex bbb799dcef2..3b1276a1746 100644--- a/apps/studio/data/projects/projects-query.ts+++ b/apps/studio/data/projects/projects-query.ts@@ -1,11 +1,11 @@import { QueryClient, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'import { useCallback, useRef } from 'react'+import { components } from 'data/api'import { get } from 'data/fetchers'import { ResponseError } from 'types'import { projectKeys } from './keys'import { Project } from './project-detail-query'-import { components } from 'data/api'export type ProjectsVariables = {ref?: string@@ -17,8 +17,7 @@ export async function getProjects(signal?: AbortSignal) {const { data, error } = await get('/platform/projects', { signal })if (error) throw error- // [Joshen] Seems like API codegen is wrong- return data as unknown as ProjectInfo[]+ return data}export type ProjectsData = Awaited<ReturnType<typeof getProjects>>diff --git a/apps/studio/pages/new/[slug].tsx b/apps/studio/pages/new/[slug].tsxindex 0d699ffe46b..c0f93850740 100644--- a/apps/studio/pages/new/[slug].tsx+++ b/apps/studio/pages/new/[slug].tsx@@ -13,16 +13,15 @@ import {import { RegionSelector } from 'components/interfaces/ProjectCreation/RegionSelector'import { WizardLayoutWithoutAuth } from 'components/layouts'import DisabledWarningDueToIncident from 'components/ui/DisabledWarningDueToIncident'-import InformationBox from 'components/ui/InformationBox'import Panel from 'components/ui/Panel'import PasswordStrengthBar from 'components/ui/PasswordStrengthBar'import { useFreeProjectLimitCheckQuery } from 'data/organizations/free-project-limit-check-query'import { useOrganizationsQuery } from 'data/organizations/organizations-query'import {+ DbInstanceSize,ProjectCreateVariables,useProjectCreateMutation,} from 'data/projects/project-create-mutation'-import { useProjectsQuery } from 'data/projects/projects-query'import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'import { useCheckPermissions, useFlag, useStore, withAuth } from 'hooks'import {@@ -36,7 +35,10 @@ import {} from 'lib/constants'import { passwordStrength, pluckObjectFields } from 'lib/helpers'import { NextPageWithLayout } from 'types'-import { Button, IconExternalLink, IconInfo, IconUsers, Input, Listbox } from 'ui'+import { Badge, Button, IconExternalLink, IconUsers, Input, Listbox } from 'ui'+import { components } from 'data/api'++type DesiredInstanceSize = components['schemas']['DesiredInstanceSize']const Wizard: NextPageWithLayout = () => {const router = useRouter()@@ -63,12 +65,14 @@ const Wizard: NextPageWithLayout = () => {const [passwordStrengthWarning, setPasswordStrengthWarning] = useState('')const [passwordStrengthScore, setPasswordStrengthScore] = useState(0)+ const [instanceSize, setInstanceSize] = useState<DbInstanceSize>('micro')+const { data: organizations, isSuccess: isOrganizationsSuccess } = useOrganizationsQuery()const currentOrg = organizations?.find((o: any) => o.slug === slug)- const { data: orgSubscription } = useOrgSubscriptionQuery({ orgSlug: slug })-- const { data: allProjects } = useProjectsQuery({})+ const { data: orgSubscription } = useOrgSubscriptionQuery({+ orgSlug: slug,+ })const {mutate: createProject,@@ -80,10 +84,6 @@ const Wizard: NextPageWithLayout = () => {},})- const orgProjectCount = (allProjects || []).filter(- (proj) => proj.organization_id === currentOrg?.id- ).length-const isAdmin = useCheckPermissions(PermissionAction.CREATE, 'projects')const isInvalidSlug = isOrganizationsSuccess && currentOrg === undefinedconst isEmptyOrganizations = (organizations?.length ?? 0) <= 0 && isOrganizationsSuccess@@ -172,7 +172,10 @@ const Wizard: NextPageWithLayout = () => {name: projectName.trim(),dbPass: dbPass,dbRegion: dbRegion,- dbPricingTierId: 'tier_free', // gets ignored due to org billing subscription anyway+ // gets ignored due to org billing subscription anyway+ dbPricingTierId: 'tier_free',+ // only set the instance size on pro+ plans. Free plans always use micro (nano in the future) size.+ dbInstanceSize: orgSubscription?.plan.id === 'free' ? undefined : instanceSize,}if (postgresVersion) {if (!postgresVersion.match(/1[2-9]\..*/)) {@@ -217,6 +220,85 @@ const Wizard: NextPageWithLayout = () => {throw new Error('Invalid cloud provider')}+ const sizes: DesiredInstanceSize[] = [+ 'micro',+ 'small',+ 'medium',+ 'large',+ 'xlarge',+ '2xlarge',+ '4xlarge',+ '8xlarge',+ '12xlarge',+ '16xlarge',+ ]++ const instanceSizeSpecs: Record<+ DesiredInstanceSize,+ { label: string; ram: string; cpu: string; price: string }+ > = {+ micro: {+ label: 'Micro',+ ram: '1 GB',+ cpu: '2-core ARM',+ price: '$0.01344/hour (~$10/month)',+ },+ small: {+ label: 'Small',+ ram: '2 GB',+ cpu: '2-core ARM',+ price: '$0.0206/hour (~$15/month)',+ },+ medium: {+ label: 'Medium',+ ram: '4 GB',+ cpu: '2-core ARM',+ price: '$0.0822/hour (~$60/month)',+ },+ large: {+ label: 'Large',+ ram: '8 GB',+ cpu: '2-core ARM',+ price: '$0.1517/hour (~$110/month)',+ },+ xlarge: {+ label: 'XL',+ ram: '16 GB',+ cpu: '4-core ARM',+ price: '$0.2877/hour (~$210/month)',+ },+ '2xlarge': {+ label: '2XL',+ ram: '32 GB',+ cpu: '8-core ARM',+ price: '$0.562/hour (~$410/month)',+ },+ '4xlarge': {+ label: '4XL',+ ram: '64 GB',+ cpu: '16-core ARM',+ price: '$1.32/hour (~$960/month)',+ },+ '8xlarge': {+ label: '8XL',+ ram: '128 GB',+ cpu: '32-core ARM',+ price: '$2.562/hour (~$1,870/month)',+ },+ '12xlarge': {+ label: '12XL',+ ram: '192 GB',+ cpu: '48-core ARM',+ price: '$3.836/hour (~$2,800/month)',+ },+ '16xlarge': {+ label: '16XL',+ ram: '256 GB',+ cpu: '64-core ARM',+ price: '$5.12/hour (~$3,730/month)',+ },+ }+return (<PanelhideHeaderStyling@@ -371,6 +453,91 @@ const Wizard: NextPageWithLayout = () => {</Panel.Content>)}+ {orgSubscription?.plan.id !== 'free' && (+ <Panel.Content+ className={[+ 'border-b',+ 'border-panel-border-interior-light [[data-theme*=dark]_&]:border-panel-border-interior-dark',+ ].join(' ')}+ >+ <Listbox+ layout="horizontal"+ label={+ <div className="space-y-4">+ <span>Instance Size</span>++ <div className="flex flex-col space-y-2">+ <Link+ href="https://supabase.com/docs/guides/platform/compute-add-ons"+ target="_blank"+ >+ <div className="flex items-center space-x-2 opacity-75 hover:opacity-100 transition">+ <p className="text-sm m-0">Compute Add-Ons</p>+ <IconExternalLink size={16} strokeWidth={1.5} />+ </div>+ </Link>++ <Link+ href="https://supabase.com/docs/guides/platform/org-based-billing#usage-based-billing-for-compute"+ target="_blank"+ >+ <div className="flex items-center space-x-2 opacity-75 hover:opacity-100 transition">+ <p className="text-sm m-0">Compute Billing</p>+ <IconExternalLink size={16} strokeWidth={1.5} />+ </div>+ </Link>+ </div>+ </div>+ }+ type="select"+ value={instanceSize}+ onChange={(value) => setInstanceSize(value)}+ descriptionText={+ <>+ <p>+ Select the size for your dedicated database. You can always change this+ later.+ </p>+ <p className="mt-1">+ Your organization has $10/month in Compute Credits to cover one instance+ on Micro Compute or parts of any other instance size.+ </p>+ </>+ }+ >+ {sizes.map((option) => {+ return (+ <Listbox.Option+ key={option}+ label={`${instanceSizeSpecs[option].ram} RAM / ${instanceSizeSpecs[option].cpu} CPU (${instanceSizeSpecs[option].label})`}+ value={option}+ >+ <div className="flex space-x-2">+ <div className="text-center w-[80px]">+ <Badge+ color={option === 'micro' ? 'gray' : 'brand'}+ className="rounded-md w-16 text-center flex justify-center font-mono uppercase"+ >+ {instanceSizeSpecs[option].label}+ </Badge>+ </div>+ <div className="text-sm">+ <span className="text-foreground">+ {instanceSizeSpecs[option].ram} RAM /{' '}+ {instanceSizeSpecs[option].cpu} CPU+ </span>+ <p className="text-xs text-muted">+ {instanceSizeSpecs[option].price}+ </p>+ </div>+ </div>+ </Listbox.Option>+ )+ })}+ </Listbox>+ </Panel.Content>+ )}+<Panel.Content className="border-b border-panel-border-interior-light [[data-theme*=dark]_&]:border-panel-border-interior-dark"><Inputid="password"@@ -403,66 +570,6 @@ const Wizard: NextPageWithLayout = () => {</>)}- <Panel.Content>- <InformationBox- icon={<IconInfo size="large" strokeWidth={1.5} />}- defaultVisibility={true}- hideCollapse- title="Billed via organization"- description={- <div className="space-y-3">- <p className="text-sm leading-normal">- This organization uses the new organization-based billing and is on the{' '}- <span className="text-brand">{orgSubscription?.plan?.name} plan</span>.- </p>-- {/* Show info when launching a new project in a paid org that has no project yet */}- {orgSubscription?.plan?.id !== 'free' && orgProjectCount === 0 && (- <div>- <p>- As this is the first project you're launching in this organization, it- comes with no additional compute costs.- </p>- </div>- )}-- {/* Show info when launching a new project in a paid org that already has at least one project */}- {orgSubscription?.plan?.id !== 'free' && orgProjectCount > 0 && (- <div>- <p>- Launching another project incurs additional compute costs, starting at- $0.01344 per hour (~$10/month). You can also create a new organization- under the free plan in case you have not exceeded your 2 free project- limit.- </p>- </div>- )}-- <div className="space-x-3">- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>- <Link- href="https://supabase.com/blog/organization-based-billing"- target="_blank"- rel="noreferrer"- >- Announcement- </Link>- </Button>- <Button asChild type="default" icon={<IconExternalLink strokeWidth={1.5} />}>- <Link- href="https://supabase.com/docs/guides/platform/org-based-billing"- target="_blank"- rel="noreferrer"- >- Documentation- </Link>- </Button>- </div>- </div>- }- />- </Panel.Content>-{isAdmin && (<Panel.Content>{freePlanWithExceedingLimits && slug && (diff --git a/packages/ui/src/components/Listbox/Listbox2.tsx b/packages/ui/src/components/Listbox/Listbox2.tsxindex 42c96e7c8c8..498c8fadab1 100644--- a/packages/ui/src/components/Listbox/Listbox2.tsx+++ b/packages/ui/src/components/Listbox/Listbox2.tsx@@ -19,7 +19,7 @@ export interface Props extends Omit<React.InputHTMLAttributes<HTMLButtonElement>error?: stringicon?: anyid?: string- label?: string+ label?: string | React.ReactNodelabelOptional?: stringlayout?: 'horizontal' | 'vertical'style?: React.CSSProperties