Skip to content

Commit

Permalink
feat: init DB schema
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Hivert <[email protected]>
  • Loading branch information
ghivert committed Apr 12, 2024
1 parent 889bb5d commit 1cc78fa
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- migrate:up
create extension if not exists "uuid-ossp";
create extension if not exists "moddatetime";

-- migrate:down
drop extension if exists "uuid-ossp";
drop extension if exists "moddatetime";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- migrate:up
create table package (
id integer primary key generated always as identity,
name text not null,
repository text,
documentation text
);

-- migrate:down
drop table package;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- migrate:up
create table package_version (
id integer primary key generated always as identity,
package_id int references package(id),
version text not null
);

-- migrate:down
drop table package_version;
12 changes: 12 additions & 0 deletions apps/backend/db/migrations/20240412155057_create_signature.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- migrate:up
create table signature (
id integer primary key generated always as identity,
package_id int references package(id),
package_version_id int references package_version(id),
name text not null,
content text not null,
comment text
);

-- migrate:down
drop table signature;
201 changes: 201 additions & 0 deletions apps/backend/db/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: moddatetime; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS moddatetime WITH SCHEMA public;


--
-- Name: EXTENSION moddatetime; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION moddatetime IS 'functions for tracking last modification time';


--
-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;


--
-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';


SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: package; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.package (
id integer NOT NULL,
name text NOT NULL,
repository text,
documentation text
);


--
-- Name: package_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.package ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.package_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);


--
-- Name: package_version; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.package_version (
id integer NOT NULL,
package_id integer,
version text NOT NULL
);


--
-- Name: package_version_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.package_version ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.package_version_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);


--
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.schema_migrations (
version character varying(128) NOT NULL
);


--
-- Name: signature; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.signature (
id integer NOT NULL,
package_id integer,
package_version_id integer,
name text NOT NULL,
content text NOT NULL,
comment text
);


--
-- Name: signature_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.signature ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.signature_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);


--
-- Name: package package_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.package
ADD CONSTRAINT package_pkey PRIMARY KEY (id);


--
-- Name: package_version package_version_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.package_version
ADD CONSTRAINT package_version_pkey PRIMARY KEY (id);


--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.schema_migrations
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);


--
-- Name: signature signature_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.signature
ADD CONSTRAINT signature_pkey PRIMARY KEY (id);


--
-- Name: package_version package_version_package_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.package_version
ADD CONSTRAINT package_version_package_id_fkey FOREIGN KEY (package_id) REFERENCES public.package(id);


--
-- Name: signature signature_package_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.signature
ADD CONSTRAINT signature_package_id_fkey FOREIGN KEY (package_id) REFERENCES public.package(id);


--
-- Name: signature signature_package_version_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.signature
ADD CONSTRAINT signature_package_version_id_fkey FOREIGN KEY (package_version_id) REFERENCES public.package_version(id);


--
-- PostgreSQL database dump complete
--


--
-- Dbmate schema migrations
--

INSERT INTO public.schema_migrations (version) VALUES
('20240412153209'),
('20240412154007'),
('20240412154430'),
('20240412155057');
3 changes: 2 additions & 1 deletion apps/backend/scripts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const writeDotEnv = async () => {
await Promise.all(envs.map(async ([envPath, dbName]) => {
const content = await dotenv.load({ envPath })
const dbUrl = ['postgres://postgres:gling@localhost:5432', dbName].join('/')
const newContent: Record<string, string> = { ...content, DATABASE_URL: dbUrl }
const sslDisabled = [dbUrl, 'sslmode=disable'].join('?')
const newContent: Record<string, string> = { ...content, DATABASE_URL: sslDisabled }
await Deno.writeTextFile(envPath, dotenv.stringify(newContent))
}))
console.info('✏️ .env and .env.test correctly initialized!')
Expand Down

0 comments on commit 1cc78fa

Please sign in to comment.