Skip to content

Commit 2a7d07e

Browse files
authored
Dev (#308)
* update dev utils * example pag * typo fix and comments * update api * update * update * notes * generate e2e data with serial ids * test push
1 parent 8dac8af commit 2a7d07e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1889
-274
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ linters:
4040
- structcheck
4141
- unparam
4242
- wastedassign
43+
# broken --fix for generated code
44+
- tagalign
4345

4446
linters-settings:
4547
errcheck:

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"go.lintFlags": [
55
"--config=${workspaceFolder}/.golangci.yml",
66
"--issues-exit-code=0",
7-
// golangci possibly broke generated code skipping in recent releases
8-
"--fix",
7+
// golangci possibly broke generated code skipping in recent releases.
8+
// "--fix",
99
"--fast" // breaks some linters like errcheck, if its too slow then enable back
1010
],
1111
"go.lintOnSave": "package",

bin/project

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,8 +1866,7 @@ x.dev-utils.api-keys() {
18661866
# to ease further updates to comments in migrations.
18671867
x.dev-utils.show-column-comments() {
18681868
local query="SELECT DISTINCT
1869-
c.relname as table,
1870-
a.attname::varchar AS column,
1869+
c.relname || '.' || a.attname AS column,
18711870
COALESCE(col_description(format('%s.%s', n.nspname, c.relname)::regclass::oid, isc.ordinal_position), '') as column_comment
18721871
FROM pg_attribute a
18731872
JOIN ONLY pg_class c ON c.oid = a.attrelid
@@ -2903,7 +2902,7 @@ if [[ -n "$1" ]]; then
29032902
err_code=$?
29042903

29052904
if test -f "$failed_tool_build_marker"; then
2906-
echo "${YELLOW}[WARNING] At least one gen tool build failed. A gen rerun may be required"
2905+
err "At least one gen tool build failed. A gen rerun may be required"
29072906
fi
29082907

29092908
exit $err_code # do not quote

cmd/initial-data/e2e/models.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package e2e
22

3-
import "github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/models"
3+
import (
4+
"github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/models"
5+
"github.com/danicc097/openapi-go-gin-postgres-sqlc/internal/repos/postgresql/gen/db"
6+
)
47

58
/*
69
NOTE: tygo just looks the ast from the current package.
710
All spec models available in tstype as `models` namespace
811
*/
912

13+
// User ids are uuids, therefore we can use any unique column for
14+
// e2e identifiers, which is also easier to reason about.
1015
type User struct {
1116
Username string `json:"username"`
1217
Email string `json:"email"`
@@ -16,7 +21,10 @@ type User struct {
1621
Role models.Role `json:"role" tstype:"models.Role"`
1722
}
1823

24+
// TODO: should include ids for the rest of entities with serial ids,
25+
// given that e2e data will not be created concurrently.
1926
type Team struct {
27+
TeamID db.TeamID `json:"teamID" tstype:"EntityIDs.TeamID"`
2028
Name string `json:"name"`
2129
ProjectName models.ProjectName `json:"projectName" tstype:"models.Project"`
2230
}

cmd/initial-data/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,18 @@ func main() {
200200
**/
201201
logger.Info("Creating activities...")
202202

203-
activity1, err := svc.Activity.Create(ctx, pool, &db.ActivityCreateParams{
204-
ProjectID: internal.ProjectIDByName[models.ProjectDemo],
203+
activity1, err := svc.Activity.Create(ctx, pool, models.ProjectDemo, &db.ActivityCreateParams{
205204
Name: "Activity 1",
206205
Description: "Activity 1 description",
207206
IsProductive: true,
208207
})
209208
handleError(err, activity1)
210-
activity2, err := svc.Activity.Create(ctx, pool, &db.ActivityCreateParams{
211-
ProjectID: internal.ProjectIDByName[models.ProjectDemo],
209+
activity2, err := svc.Activity.Create(ctx, pool, models.ProjectDemo, &db.ActivityCreateParams{
212210
Name: "Activity 2",
213211
Description: "Activity 2 description",
214212
})
215213
handleError(err, activity2)
216-
activity3, err := svc.Activity.Create(ctx, pool, &db.ActivityCreateParams{
217-
ProjectID: internal.ProjectIDByName[models.ProjectDemo],
214+
activity3, err := svc.Activity.Create(ctx, pool, models.ProjectDemo, &db.ActivityCreateParams{
218215
Name: "Activity 3",
219216
Description: "Activity 3 description",
220217
})
@@ -459,8 +456,10 @@ func main() {
459456
"uuid.NullUUID": "null | string /* uuid */",
460457
},
461458
// to import actual values from models package, do it explicitly
462-
Frontmatter: `import type * as models from "client/gen/model";`,
463-
OutputPath: path.Join(e2eTestDataDir, "initial-data.ts"),
459+
Frontmatter: `import type * as models from "client/gen/model";
460+
import type * as EntityIDs from "./entity-ids";
461+
`,
462+
OutputPath: path.Join(e2eTestDataDir, "initial-data.ts"),
464463
},
465464
},
466465
}
@@ -487,6 +486,7 @@ func main() {
487486
tt := make([]e2e.Team, len(teams))
488487
for i, t := range teams {
489488
tt[i] = e2e.Team{
489+
TeamID: t.TeamID,
490490
Name: t.Name,
491491
ProjectName: t.ProjectJoin.Name,
492492
}

e2e/__tests__/data/entity-ids.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../frontend/src/gen/entity-ids.ts

e2e/__tests__/data/initial-data.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// Code generated by tygo. DO NOT EDIT.
22
import type * as models from "client/gen/model";
3+
import type * as EntityIDs from "./entity-ids";
4+
35
//////////
46
// source: models.go
57

8+
/**
9+
* User ids are uuids, therefore we can use any unique column for
10+
* e2e identifiers, which is also easier to reason about.
11+
*/
612
export interface User {
713
username: string;
814
email: string;
@@ -11,7 +17,12 @@ export interface User {
1117
scopes: models.Scopes;
1218
role: models.Role;
1319
}
20+
/**
21+
* TODO: should include ids for the rest of entities with serial ids,
22+
* given that e2e data will not be created concurrently.
23+
*/
1424
export interface Team {
25+
teamID: EntityIDs.TeamID;
1526
name: string;
1627
projectName: models.Project;
1728
}

e2e/__tests__/data/teams.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
[
22
{
3+
"teamID": 1,
34
"name": "Team 1",
45
"projectName": "demo"
56
},
67
{
8+
"teamID": 2,
79
"name": "Team 2-1",
810
"projectName": "demo_two"
911
},
1012
{
13+
"teamID": 3,
1114
"name": "Team 2-2",
1215
"projectName": "demo_two"
1316
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Generated by orval v6.23.0 🍺
3+
* Do not edit manually.
4+
* OpenAPI openapi-go-gin-postgres-sqlc
5+
* openapi-go-gin-postgres-sqlc
6+
* OpenAPI spec version: 2.0.0
7+
*/
8+
import type { CacheDemoWorkItemMetadata } from './cacheDemoWorkItemMetadata'
9+
10+
export interface CacheDemoWorkItem {
11+
closedAt?: Date | null
12+
createdAt: Date
13+
deletedAt?: Date | null
14+
description: string
15+
kanbanStepID: number
16+
lastMessageAt: Date
17+
line: string
18+
metadata: CacheDemoWorkItemMetadata
19+
ref: string
20+
reopened: boolean
21+
targetDate: Date
22+
teamID: number
23+
title: string
24+
updatedAt: Date
25+
workItemID: number
26+
workItemTypeID: number
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Generated by orval v6.23.0 🍺
3+
* Do not edit manually.
4+
* OpenAPI openapi-go-gin-postgres-sqlc
5+
* openapi-go-gin-postgres-sqlc
6+
* OpenAPI spec version: 2.0.0
7+
*/
8+
9+
export type CacheDemoWorkItemMetadata = { [key: string]: unknown }

0 commit comments

Comments
 (0)