-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { z } from 'zod' | ||
|
||
export const attributeSupplementSchema = { | ||
accessInstructions: z.object({ | ||
access_type: z.enum(['email', 'file', 'link', 'location', 'other', 'phone']), | ||
access_value: z.union([z.string(), z.null()]).optional(), | ||
instructions: z.string(), | ||
}), | ||
currency: z.any(), | ||
incompatible: z.any(), | ||
incompatibleData: z.array(z.record(z.any())), | ||
number: z.object({ num: z.number() }), | ||
'num-max': z.any(), | ||
numMax: z.object({ max: z.number() }), | ||
'num-min': z.any(), | ||
numMin: z.object({ min: z.number() }), | ||
'num-min-max': z.any(), | ||
numMinMaxOrRange: z.union([ | ||
z.object({ min: z.number() }), | ||
z.object({ max: z.number() }), | ||
z.object({ max: z.number(), min: z.number() }), | ||
]), | ||
numRange: z.object({ max: z.number(), min: z.number() }), | ||
otherDescribe: z.object({ other: z.string() }), | ||
} | ||
|
||
export const isAttributeSupplementSchema = (schema: string): schema is AttributeSupplementSchemas => | ||
Object.keys(attributeSupplementSchema).includes(schema) | ||
|
||
export type AttributeSupplementSchemas = keyof typeof attributeSupplementSchema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type JsonSchemaObject, jsonSchemaToZod } from 'json-schema-to-zod' | ||
|
||
import { prisma } from '~db/client' | ||
import { type ListrTask } from '~db/lib/generateData' | ||
|
||
import { writeOutput } from './common' | ||
|
||
export const generateDataSchemas = async (task: ListrTask) => { | ||
const data = await prisma.attributeSupplementDataSchema.findMany({ | ||
where: { | ||
active: true, | ||
}, | ||
select: { | ||
tag: true, | ||
schema: true, | ||
}, | ||
orderBy: { tag: 'asc' }, | ||
}) | ||
const schemas = data.map(({ tag, schema }) => { | ||
return `"${tag}": ${jsonSchemaToZod(schema as JsonSchemaObject)},` | ||
}) | ||
|
||
const out = ` | ||
import { z } from 'zod'; | ||
export const attributeSupplementSchema = { | ||
${schemas.join('\n')} | ||
} | ||
export const isAttributeSupplementSchema = (schema: string): schema is AttributeSupplementSchemas => Object.keys(attributeSupplementSchema).includes(schema) | ||
export type AttributeSupplementSchemas = keyof typeof attributeSupplementSchema | ||
` | ||
await writeOutput('attributeSupplementSchema', out) | ||
task.title = `${task.title} (${data.length} items)` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/db/prisma/migrations/20240214173007_attribute_supplement_schemas/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `schema` to the `AttributeSupplementDataSchema` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "AttributeSupplementDataSchema" | ||
ADD COLUMN "schema" JSONB; | ||
|
||
UPDATE | ||
"AttributeSupplementDataSchema" | ||
SET | ||
"schema" = "definition"; | ||
|
||
ALTER TABLE "AttributeSupplementDataSchema" | ||
ALTER COLUMN "schema" SET NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "AttributeSupplement_active_attributeId_idx" ON | ||
"AttributeSupplement"("active", "attributeId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "OrgLocationService_active_serviceId_idx" ON | ||
"OrgLocationService"("active", "serviceId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "OrgService_organizationId_published_deleted_idx" ON | ||
"OrgService"("organizationId", "published" DESC, "deleted"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "ServiceArea_active_organizationId_idx" ON | ||
"ServiceArea"("active", "organizationId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "ServiceArea_active_orgLocationId_idx" ON | ||
"ServiceArea"("active", "orgLocationId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "ServiceArea_active_orgServiceId_idx" ON | ||
"ServiceArea"("active", "orgServiceId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "ServiceAreaCountry_active_serviceAreaId_idx" ON | ||
"ServiceAreaCountry"("active", "serviceAreaId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX IF NOT EXISTS "ServiceAreaDist_active_serviceAreaId_idx" ON | ||
"ServiceAreaDist"("active", "serviceAreaId"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.