Skip to content

Commit

Permalink
Merge pull request #34 from badgeteam/feature/26-upload-api-part-3
Browse files Browse the repository at this point in the history
Upload API Prep Part 3: Add Project and User Insert API
  • Loading branch information
francisduvivier authored Dec 9, 2024
2 parents cb7ab9a + a57a210 commit ea9f1da
Show file tree
Hide file tree
Showing 17 changed files with 1,576 additions and 117 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,
id serial primary key,
email text unique,
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
40 changes: 38 additions & 2 deletions mockup-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -192,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 @@ -206,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 @@ -224,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 @@ -329,6 +351,13 @@ ALTER TABLE ONLY badgehub.migrations ALTER COLUMN id SET DEFAULT nextval('badgeh
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 @@ -892,6 +921,13 @@ SELECT pg_catalog.setval('badgehub.migrations_id_seq', 1, 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
--
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test-db:up": "docker compose -f docker-compose.test-db.yml up -d --wait",
"test-db:down": "docker compose -f docker-compose.test-db.yml down",
"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
Loading

0 comments on commit ea9f1da

Please sign in to comment.