Skip to content

Commit

Permalink
Change user id back to number like other id's
Browse files Browse the repository at this point in the history
  • Loading branch information
Francis Duvivier committed Nov 27, 2024
1 parent 4bce61d commit dae68e1
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 22 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions migrations/sqls/20241116085102-initialize-up.sql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down
89 changes: 76 additions & 13 deletions mockup-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,36 @@ 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
);


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
--
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
--
Expand Down Expand Up @@ -293,13 +337,27 @@ 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
--

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
--
Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -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
\.


Expand Down Expand Up @@ -850,13 +907,27 @@ 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
--

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
--
Expand Down Expand Up @@ -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
--
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/db/BadgeHubDataPostgresAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class BadgeHubDataPostgresAdapter implements BadgeHubDataPort {
};
}

getUser(userId: string): Promise<User> {
getUser(userId: User["id"]): Promise<User> {
throw new Error("Method not implemented.");
}

Expand Down
2 changes: 1 addition & 1 deletion src/db/models/app/DBUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface UserRelation {
user_id: DBUser["id"];
}
export interface DBInsertUser {
id: string;
id: number;
email: string;
admin?: boolean;
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/domain/readModels/app/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface UserRelation {
}

export interface User extends DatedData {
id: string;
id: number;
email: string;
admin: boolean;
name: string;
Expand Down

0 comments on commit dae68e1

Please sign in to comment.