Skip to content

Commit 2d0d513

Browse files
Scripts: Complete (PalisadoesFoundation#3356)
* added id column * basic test * test ping * code quality * added more cases * final * environment configured * quality * dynamicity * completely dynamic * final fix * debug * code quality * debug level high * added bucket name in testing env * fix * bucket name * api service env * validate approval * coderabbit fix * doc fix --------- Co-authored-by: JaiPannu-IITI <[email protected]>
1 parent 0461912 commit 2d0d513

File tree

10 files changed

+339
-22
lines changed

10 files changed

+339
-22
lines changed

.coderabbit.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ reviews:
1212
high_level_summary: true
1313
review_status: true
1414
collapse_walkthrough: false
15-
request_changes_workflow: true
1615
auto_review:
1716
enabled: true
1817
drafts: false

docker/compose.testing.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ services:
2525
environment:
2626
- API_MINIO_TEST_END_POINT=${API_MINIO_TEST_END_POINT:?error}
2727
- API_POSTGRES_TEST_HOST=${API_POSTGRES_TEST_HOST:?error}
28+
- MINIO_ROOT_USER=${MINIO_ROOT_USER:?error}
2829
# https://docs.docker.com/reference/dockerfile/#healthcheck
2930
# https://docs.docker.com/reference/compose-file/services/#healthcheck
3031
healthcheck:

docs/docs/docs/getting-started/installation.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,6 @@ This applies to users running Talawa API in dev containers.
397397
```bash
398398
docker exec talawa-api-1 /bin/bash -c 'pnpm run add:sample_data && exit'
399399
```
400-
4. Then exit
401-
```bash
402-
exit
403-
```
404400
Refer to the next section for login information.
405401

406402
### Sample Data Users

drizzle_migrations/20250122092015_sweet_scrambler.sql renamed to drizzle_migrations/20250311060842_lean_misty_knight.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ CREATE TABLE "organizations" (
275275
--> statement-breakpoint
276276
CREATE TABLE "post_attachments" (
277277
"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
278+
"id" uuid PRIMARY KEY NOT NULL,
278279
"creator_id" uuid,
279280
"post_id" uuid NOT NULL,
280281
"mime_type" text NOT NULL,

drizzle_migrations/meta/20250122092015_snapshot.json renamed to drizzle_migrations/meta/20250311060842_snapshot.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "e5fe635f-2302-4a95-86e6-16508bb68c63",
2+
"id": "41d3c6f8-89e8-438f-bd91-4802134c00ad",
33
"prevId": "00000000-0000-0000-0000-000000000000",
44
"version": "7",
55
"dialect": "postgresql",
@@ -4084,6 +4084,12 @@
40844084
"notNull": true,
40854085
"default": "now()"
40864086
},
4087+
"id": {
4088+
"name": "id",
4089+
"type": "uuid",
4090+
"primaryKey": true,
4091+
"notNull": true
4092+
},
40874093
"creator_id": {
40884094
"name": "creator_id",
40894095
"type": "uuid",

drizzle_migrations/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
{
66
"idx": 0,
77
"version": "7",
8-
"when": 1737537615071,
9-
"tag": "20250122092015_sweet_scrambler",
8+
"when": 1741673322722,
9+
"tag": "20250311060842_lean_misty_knight",
1010
"breakpoints": true
1111
}
1212
]

scripts/dbManagement/helpers.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const queryClient = postgres({
3535
});
3636

3737
//Create a bucket client
38-
const minioClient = new MinioClient({
38+
export const minioClient = new MinioClient({
3939
accessKey: envConfig.API_MINIO_ACCESS_KEY || "",
4040
endPoint: envConfig.API_MINIO_END_POINT || "",
4141
port: Number(envConfig.API_MINIO_PORT),
@@ -98,7 +98,7 @@ export async function formatDatabase(): Promise<boolean> {
9898

9999
await tx.execute(sql`
100100
DELETE FROM ${sql.identifier(USERS_TABLE)}
101-
WHERE email != ${adminEmail};
101+
WHERE email_address != ${adminEmail};
102102
`);
103103
});
104104

@@ -233,6 +233,7 @@ export async function insertCollections(
233233

234234
const API_ADMINISTRATOR_USER_EMAIL_ADDRESS =
235235
envConfig.API_ADMINISTRATOR_USER_EMAIL_ADDRESS;
236+
236237
if (!API_ADMINISTRATOR_USER_EMAIL_ADDRESS) {
237238
throw new Error(
238239
"\x1b[31mAPI_ADMINISTRATOR_USER_EMAIL_ADDRESS is not defined.\x1b[0m",
@@ -399,16 +400,12 @@ export async function insertCollections(
399400
createdAt: parseDate(post_attachment.createdAt),
400401
}),
401402
) as (typeof schema.postAttachmentsTable.$inferInsert)[];
402-
try {
403-
// Post Attachements are not unique. So they are inserted without checking for duplicates.
404-
await db
405-
.insert(schema.postAttachmentsTable)
406-
.values(post_attachments);
407-
} catch {
408-
throw new Error(
409-
"\x1b[31mError inserting post_attachments data\x1b[0m",
410-
);
411-
}
403+
await checkAndInsertData(
404+
schema.postAttachmentsTable,
405+
post_attachments,
406+
schema.postAttachmentsTable.id,
407+
1000,
408+
);
412409
// Handle file uploads to Minio.
413410
await Promise.all(
414411
post_attachments.map(async (attachment) => {

src/drizzle/tables/postAttachments.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { relations, sql } from "drizzle-orm";
22
import { index, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
33
import { createInsertSchema } from "drizzle-zod";
4+
import { uuidv7 } from "uuidv7";
45
import { postAttachmentMimeTypeEnum } from "~/src/drizzle/enums/postAttachmentMimeType";
56
import { postsTable } from "./posts";
67
import { usersTable } from "./users";
7-
88
/**
99
* Drizzle orm postgres table definition for post attachments.
1010
*/
@@ -21,6 +21,11 @@ export const postAttachmentsTable = pgTable(
2121
})
2222
.notNull()
2323
.defaultNow(),
24+
/**
25+
* Primary unique identifier of the post attachment.
26+
*/
27+
id: uuid("id").primaryKey().$default(uuidv7),
28+
2429
/**
2530
* Foreign key reference to the id of the user who created the attachment.
2631
*/

test/envConfigSchema.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type Static, Type } from "@sinclair/typebox";
2+
import envSchema from "env-schema";
23
import { envConfigSchema } from "~/src/envConfigSchema";
3-
4+
import { envSchemaAjv } from "~/src/envConfigSchema";
45
/**
56
* JSON schema of a record of environment variables accessible to the talawa api tests at runtime.
67
*/
@@ -13,6 +14,13 @@ export const testEnvConfigSchema = Type.Object({
1314
* More information at this link: {@link https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-HOST}
1415
*/
1516
API_POSTGRES_TEST_HOST: envConfigSchema.properties.API_POSTGRES_HOST,
17+
18+
MINIO_ROOT_USER: envConfigSchema.properties.MINIO_ROOT_USER,
19+
});
20+
export const testEnvConfig = envSchema<TestEnvConfig>({
21+
ajv: envSchemaAjv,
22+
dotenv: true,
23+
schema: testEnvConfigSchema,
1624
});
1725

1826
/**

0 commit comments

Comments
 (0)