Skip to content

Commit 31cc528

Browse files
committed
feat: github users table
1 parent b8ebab7 commit 31cc528

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @param { import("knex").Knex } knex
3+
* @returns { Promise<void> }
4+
*/
5+
exports.up = async (knex) => {
6+
await knex.schema.createTable('github_users', (table) => {
7+
table.increments('id').primary() // Primary key
8+
table.string('name')
9+
table.string('email')
10+
table.string('login').notNullable()
11+
table.string('github_user_id').unique().notNullable()
12+
table.string('node_id').notNullable()
13+
table.string('avatar_url')
14+
table.string('gravatar_id')
15+
table.string('url')
16+
table.string('html_url')
17+
table.string('followers_url')
18+
table.string('following_url')
19+
table.string('starred_url')
20+
table.string('subscriptions_url')
21+
table.string('organizations_url')
22+
table.string('repos_url')
23+
table.string('events_url')
24+
table.string('received_events_url')
25+
table.string('type')
26+
table.boolean('site_admin').notNullable()
27+
table.string('starred_at')
28+
table.string('user_view_type')
29+
table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable()
30+
table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable()
31+
})
32+
33+
// Add trigger to 'github_organizations' table
34+
await knex.raw(`
35+
CREATE TRIGGER set_updated_at_github_users
36+
BEFORE UPDATE ON github_users
37+
FOR EACH ROW
38+
EXECUTE FUNCTION update_updated_at_column();
39+
`)
40+
}
41+
42+
/**
43+
* @param { import("knex").Knex } knex
44+
* @returns { Promise<void> }
45+
*/
46+
exports.down = async (knex) => {
47+
// Drop triggers
48+
await knex.raw('DROP TRIGGER IF EXISTS set_updated_at_github_users ON github_users;')
49+
// Drop table
50+
await knex.schema.dropTableIfExists('github_users')
51+
}

src/database/schema/schema.sql

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,58 @@ CREATE SEQUENCE public.github_repositories_id_seq
479479
ALTER SEQUENCE public.github_repositories_id_seq OWNED BY public.github_repositories.id;
480480

481481

482+
--
483+
-- Name: github_users; Type: TABLE; Schema: public; Owner: -
484+
--
485+
486+
CREATE TABLE public.github_users (
487+
id integer NOT NULL,
488+
name character varying(255),
489+
email character varying(255),
490+
login character varying(255) NOT NULL,
491+
github_user_id character varying(255) NOT NULL,
492+
node_id character varying(255) NOT NULL,
493+
avatar_url character varying(255),
494+
gravatar_id character varying(255),
495+
url character varying(255),
496+
html_url character varying(255),
497+
followers_url character varying(255),
498+
following_url character varying(255),
499+
starred_url character varying(255),
500+
subscriptions_url character varying(255),
501+
organizations_url character varying(255),
502+
repos_url character varying(255),
503+
events_url character varying(255),
504+
received_events_url character varying(255),
505+
type character varying(255),
506+
site_admin boolean NOT NULL,
507+
starred_at character varying(255),
508+
user_view_type character varying(255),
509+
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
510+
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
511+
);
512+
513+
514+
--
515+
-- Name: github_users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
516+
--
517+
518+
CREATE SEQUENCE public.github_users_id_seq
519+
AS integer
520+
START WITH 1
521+
INCREMENT BY 1
522+
NO MINVALUE
523+
NO MAXVALUE
524+
CACHE 1;
525+
526+
527+
--
528+
-- Name: github_users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
529+
--
530+
531+
ALTER SEQUENCE public.github_users_id_seq OWNED BY public.github_users.id;
532+
533+
482534
--
483535
-- Name: knex_migrations; Type: TABLE; Schema: public; Owner: -
484536
--
@@ -893,6 +945,13 @@ ALTER TABLE ONLY public.github_organizations ALTER COLUMN id SET DEFAULT nextval
893945
ALTER TABLE ONLY public.github_repositories ALTER COLUMN id SET DEFAULT nextval('public.github_repositories_id_seq'::regclass);
894946

895947

948+
--
949+
-- Name: github_users id; Type: DEFAULT; Schema: public; Owner: -
950+
--
951+
952+
ALTER TABLE ONLY public.github_users ALTER COLUMN id SET DEFAULT nextval('public.github_users_id_seq'::regclass);
953+
954+
896955
--
897956
-- Name: knex_migrations id; Type: DEFAULT; Schema: public; Owner: -
898957
--
@@ -1054,6 +1113,22 @@ ALTER TABLE ONLY public.github_repositories
10541113
ADD CONSTRAINT github_repositories_pkey PRIMARY KEY (id);
10551114

10561115

1116+
--
1117+
-- Name: github_users github_users_github_user_id_unique; Type: CONSTRAINT; Schema: public; Owner: -
1118+
--
1119+
1120+
ALTER TABLE ONLY public.github_users
1121+
ADD CONSTRAINT github_users_github_user_id_unique UNIQUE (github_user_id);
1122+
1123+
1124+
--
1125+
-- Name: github_users github_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
1126+
--
1127+
1128+
ALTER TABLE ONLY public.github_users
1129+
ADD CONSTRAINT github_users_pkey PRIMARY KEY (id);
1130+
1131+
10571132
--
10581133
-- Name: knex_migrations_lock knex_migrations_lock_pkey; Type: CONSTRAINT; Schema: public; Owner: -
10591134
--
@@ -1173,6 +1248,13 @@ CREATE TRIGGER set_updated_at_github_organizations BEFORE UPDATE ON public.githu
11731248
CREATE TRIGGER set_updated_at_github_repositories BEFORE UPDATE ON public.github_repositories FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();
11741249

11751250

1251+
--
1252+
-- Name: github_users set_updated_at_github_users; Type: TRIGGER; Schema: public; Owner: -
1253+
--
1254+
1255+
CREATE TRIGGER set_updated_at_github_users BEFORE UPDATE ON public.github_users FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();
1256+
1257+
11761258
--
11771259
-- Name: ossf_scorecard_results set_updated_at_ossf_scorecard_results; Type: TRIGGER; Schema: public; Owner: -
11781260
--

0 commit comments

Comments
 (0)