From dae68e1f946827bad9d229440b7a9046b2de5785 Mon Sep 17 00:00:00 2001 From: Francis Duvivier Date: Wed, 27 Nov 2024 21:53:59 +0100 Subject: [PATCH] Change user id back to number like other id's --- README.md | 8 +- .../sqls/20241116085102-initialize-up.sql | 13 +-- mockup-data.sql | 89 ++++++++++++++++--- package.json | 1 + src/db/BadgeHubDataPostgresAdapter.ts | 2 +- src/db/models/app/DBUser.ts | 2 +- src/domain/readModels/app/User.ts | 2 +- 7 files changed, 95 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 0f8968d..769c4d9 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,13 @@ For the mock data, we always want up to date tables, so after you have done the You can do this with the pg_dump command in the postgres container: ```bash -npm run backup +npm run overwrite-mockup-data +``` + +Note: you might have to change the db container name in the script. Eg on mac with podman its with underscores instead of dashes which makes the command: + +```bash +docker exec -it badgehub-api_db_1 /usr/bin/pg_dump --username badgehub --schema badgehub badgehub > mockup-data.sql ``` #### Run the down migration to test it. diff --git a/migrations/sqls/20241116085102-initialize-up.sql b/migrations/sqls/20241116085102-initialize-up.sql index d44c5b9..7fee409 100644 --- a/migrations/sqls/20241116085102-initialize-up.sql +++ b/migrations/sqls/20241116085102-initialize-up.sql @@ -1,9 +1,12 @@ -- back up with old schema alter schema badgehub rename to badgehub_old; create schema badgehub; -create table badgehub.migrations -( - like badgehub_old.migrations including all + +-- Recfreate badgehub.migrations +CREATE TABLE badgehub.migrations ( + id serial NOT NULL, + name character varying(255) NOT NULL, + run_on timestamp without time zone NOT NULL ); -- create tables @@ -19,7 +22,7 @@ create table badges create table users ( - id text primary key, -- using text as recommended + id serial primary key, email text unique, -- using text as recommended admin boolean, name text not null, @@ -40,7 +43,7 @@ create table projects updated_at timestamptz not null default now(), deleted_at timestamptz, version_id integer, - user_id text not null, + user_id integer not null, slug text not null primary key, git text, allow_team_fixes boolean, diff --git a/mockup-data.sql b/mockup-data.sql index 1d44206..968d047 100644 --- a/mockup-data.sql +++ b/mockup-data.sql @@ -114,7 +114,7 @@ ALTER TABLE badgehub.categories OWNER TO badgehub; -- CREATE TABLE badgehub.migrations ( - id integer DEFAULT nextval('badgehub_old.migrations_id_seq'::regclass) NOT NULL, + id integer NOT NULL, name character varying(255) NOT NULL, run_on timestamp without time zone NOT NULL ); @@ -122,6 +122,28 @@ CREATE TABLE badgehub.migrations ( ALTER TABLE badgehub.migrations OWNER TO badgehub; +-- +-- Name: migrations_id_seq; Type: SEQUENCE; Schema: badgehub; Owner: badgehub +-- + +CREATE SEQUENCE badgehub.migrations_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE badgehub.migrations_id_seq OWNER TO badgehub; + +-- +-- Name: migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: badgehub; Owner: badgehub +-- + +ALTER SEQUENCE badgehub.migrations_id_seq OWNED BY badgehub.migrations.id; + + -- -- Name: project_statuses_on_badges; Type: TABLE; Schema: badgehub; Owner: badgehub -- @@ -170,7 +192,7 @@ CREATE TABLE badgehub.projects ( updated_at timestamp with time zone DEFAULT now() NOT NULL, deleted_at timestamp with time zone, version_id integer, - user_id text NOT NULL, + user_id integer NOT NULL, slug text NOT NULL, git text, allow_team_fixes boolean @@ -184,7 +206,7 @@ ALTER TABLE badgehub.projects OWNER TO badgehub; -- CREATE TABLE badgehub.users ( - id text NOT NULL, + id integer NOT NULL, email text, admin boolean, name text NOT NULL, @@ -202,6 +224,28 @@ CREATE TABLE badgehub.users ( ALTER TABLE badgehub.users OWNER TO badgehub; +-- +-- Name: users_id_seq; Type: SEQUENCE; Schema: badgehub; Owner: badgehub +-- + +CREATE SEQUENCE badgehub.users_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE badgehub.users_id_seq OWNER TO badgehub; + +-- +-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: badgehub; Owner: badgehub +-- + +ALTER SEQUENCE badgehub.users_id_seq OWNED BY badgehub.users.id; + + -- -- Name: versioned_dependencies; Type: TABLE; Schema: badgehub; Owner: badgehub -- @@ -293,6 +337,13 @@ ALTER SEQUENCE badgehub.versions_id_seq OWNED BY badgehub.versions.id; ALTER TABLE ONLY badgehub.app_metadata_jsons ALTER COLUMN id SET DEFAULT nextval('badgehub.app_metadata_jsons_id_seq'::regclass); +-- +-- Name: migrations id; Type: DEFAULT; Schema: badgehub; Owner: badgehub +-- + +ALTER TABLE ONLY badgehub.migrations ALTER COLUMN id SET DEFAULT nextval('badgehub.migrations_id_seq'::regclass); + + -- -- Name: project_statuses_on_badges id; Type: DEFAULT; Schema: badgehub; Owner: badgehub -- @@ -300,6 +351,13 @@ ALTER TABLE ONLY badgehub.app_metadata_jsons ALTER COLUMN id SET DEFAULT nextval ALTER TABLE ONLY badgehub.project_statuses_on_badges ALTER COLUMN id SET DEFAULT nextval('badgehub.project_statuses_on_badges_id_seq'::regclass); +-- +-- Name: users id; Type: DEFAULT; Schema: badgehub; Owner: badgehub +-- + +ALTER TABLE ONLY badgehub.users ALTER COLUMN id SET DEFAULT nextval('badgehub.users_id_seq'::regclass); + + -- -- Name: versioned_dependencies id; Type: DEFAULT; Schema: badgehub; Owner: badgehub -- @@ -417,7 +475,6 @@ COPY badgehub.badges (slug, name, created_at, updated_at, deleted_at) FROM stdin mch2022 mch2022 2022-06-12 16:41:34+00 2022-06-12 16:41:48+00 \N troopers23 troopers23 2023-06-19 17:48:13+00 2023-06-19 17:48:13+00 \N why2025 WHY2025 2024-05-22 11:17:11.441719+00 2024-05-22 11:17:11.441719+00 \N -admin Admin \N \N \N \. @@ -449,7 +506,7 @@ sao SAO \N \N \N -- COPY badgehub.migrations (id, name, run_on) FROM stdin; -38 /20241116085102-initialize 2024-11-25 23:55:13.518 +1 /20241116085102-initialize 2024-11-27 23:56:35.535 \. @@ -850,6 +907,13 @@ COPY badgehub.versions (id, project_slug, app_metadata_json_id, revision, semant SELECT pg_catalog.setval('badgehub.app_metadata_jsons_id_seq', 87, true); +-- +-- Name: migrations_id_seq; Type: SEQUENCE SET; Schema: badgehub; Owner: badgehub +-- + +SELECT pg_catalog.setval('badgehub.migrations_id_seq', 1, true); + + -- -- Name: project_statuses_on_badges_id_seq; Type: SEQUENCE SET; Schema: badgehub; Owner: badgehub -- @@ -857,6 +921,13 @@ SELECT pg_catalog.setval('badgehub.app_metadata_jsons_id_seq', 87, true); SELECT pg_catalog.setval('badgehub.project_statuses_on_badges_id_seq', 105, true); +-- +-- Name: users_id_seq; Type: SEQUENCE SET; Schema: badgehub; Owner: badgehub +-- + +SELECT pg_catalog.setval('badgehub.users_id_seq', 1, false); + + -- -- Name: versioned_dependencies_id_seq; Type: SEQUENCE SET; Schema: badgehub; Owner: badgehub -- @@ -903,14 +974,6 @@ ALTER TABLE ONLY badgehub.categories ADD CONSTRAINT categories_pkey PRIMARY KEY (slug); --- --- Name: migrations migrations_pkey; Type: CONSTRAINT; Schema: badgehub; Owner: badgehub --- - -ALTER TABLE ONLY badgehub.migrations - ADD CONSTRAINT migrations_pkey PRIMARY KEY (id); - - -- -- Name: project_statuses_on_badges project_statuses_on_badges_pkey; Type: CONSTRAINT; Schema: badgehub; Owner: badgehub -- diff --git a/package.json b/package.json index 50356ed..0d40bdb 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "swagger": "tsoa spec-and-routes", "dev": "node --import tsx --watch src/index.ts", "backup": "docker exec -it badgehub-api-db-1 /usr/bin/pg_dump --username badgehub badgehub -f /var/backup/data-backup-`date +\"%Y-%m-%dT%H:%m\"`.sql", + "overwrite-mockup-data": "docker exec -it badgehub-api-db-1 /usr/bin/pg_dump --username badgehub --schema badgehub badgehub > mockup-data.sql", "test": "vitest --coverage.enabled true", "db-migrate:up": "db-migrate up", "db-migrate:down": "db-migrate down", diff --git a/src/db/BadgeHubDataPostgresAdapter.ts b/src/db/BadgeHubDataPostgresAdapter.ts index d799ae0..9603423 100644 --- a/src/db/BadgeHubDataPostgresAdapter.ts +++ b/src/db/BadgeHubDataPostgresAdapter.ts @@ -182,7 +182,7 @@ export class BadgeHubDataPostgresAdapter implements BadgeHubDataPort { }; } - getUser(userId: string): Promise { + getUser(userId: User["id"]): Promise { throw new Error("Method not implemented."); } diff --git a/src/db/models/app/DBUser.ts b/src/db/models/app/DBUser.ts index 53c7177..f0bc936 100644 --- a/src/db/models/app/DBUser.ts +++ b/src/db/models/app/DBUser.ts @@ -5,7 +5,7 @@ export interface UserRelation { user_id: DBUser["id"]; } export interface DBInsertUser { - id: string; + id: number; email: string; admin?: boolean; name: string; diff --git a/src/domain/readModels/app/User.ts b/src/domain/readModels/app/User.ts index fb8b0f3..0e6d094 100644 --- a/src/domain/readModels/app/User.ts +++ b/src/domain/readModels/app/User.ts @@ -5,7 +5,7 @@ export interface UserRelation { } export interface User extends DatedData { - id: string; + id: number; email: string; admin: boolean; name: string;