Skip to content
51 changes: 51 additions & 0 deletions src/database/migrations/20250224195123_github_users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async (knex) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This table is being created with the response from https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#list-organization-members, I think it makes the most sense. I don't think we need all the user information.

await knex.schema.createTable('github_users', (table) => {
table.increments('id').primary() // Primary key
table.string('name')
table.string('email')
table.string('login').notNullable()
table.string('github_user_id').unique().notNullable()
table.string('node_id').notNullable()
table.string('avatar_url')
table.string('gravatar_id')
table.string('url')
table.string('html_url')
table.string('followers_url')
table.string('following_url')
table.string('starred_url')
table.string('subscriptions_url')
table.string('organizations_url')
table.string('repos_url')
table.string('events_url')
table.string('received_events_url')
table.string('type')
table.boolean('site_admin').notNullable()
table.string('starred_at')
table.string('user_view_type')
table.timestamp('created_at').defaultTo(knex.fn.now()).notNullable()
table.timestamp('updated_at').defaultTo(knex.fn.now()).notNullable()
})

// Add trigger to 'github_organizations' table
await knex.raw(`
CREATE TRIGGER set_updated_at_github_users
BEFORE UPDATE ON github_users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
`)
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async (knex) => {
// Drop triggers
await knex.raw('DROP TRIGGER IF EXISTS set_updated_at_github_users ON github_users;')
// Drop table
await knex.schema.dropTableIfExists('github_users')
}
82 changes: 82 additions & 0 deletions src/database/schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,58 @@ CREATE SEQUENCE public.github_repositories_id_seq
ALTER SEQUENCE public.github_repositories_id_seq OWNED BY public.github_repositories.id;


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

CREATE TABLE public.github_users (
id integer NOT NULL,
name character varying(255),
email character varying(255),
login character varying(255) NOT NULL,
github_user_id character varying(255) NOT NULL,
node_id character varying(255) NOT NULL,
avatar_url character varying(255),
gravatar_id character varying(255),
url character varying(255),
html_url character varying(255),
followers_url character varying(255),
following_url character varying(255),
starred_url character varying(255),
subscriptions_url character varying(255),
organizations_url character varying(255),
repos_url character varying(255),
events_url character varying(255),
received_events_url character varying(255),
type character varying(255),
site_admin boolean NOT NULL,
starred_at character varying(255),
user_view_type character varying(255),
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


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

CREATE SEQUENCE public.github_users_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: github_users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.github_users_id_seq OWNED BY public.github_users.id;


--
-- Name: knex_migrations; Type: TABLE; Schema: public; Owner: -
--
Expand Down Expand Up @@ -893,6 +945,13 @@ ALTER TABLE ONLY public.github_organizations ALTER COLUMN id SET DEFAULT nextval
ALTER TABLE ONLY public.github_repositories ALTER COLUMN id SET DEFAULT nextval('public.github_repositories_id_seq'::regclass);


--
-- Name: github_users id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.github_users ALTER COLUMN id SET DEFAULT nextval('public.github_users_id_seq'::regclass);


--
-- Name: knex_migrations id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1054,6 +1113,22 @@ ALTER TABLE ONLY public.github_repositories
ADD CONSTRAINT github_repositories_pkey PRIMARY KEY (id);


--
-- Name: github_users github_users_github_user_id_unique; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.github_users
ADD CONSTRAINT github_users_github_user_id_unique UNIQUE (github_user_id);


--
-- Name: github_users github_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.github_users
ADD CONSTRAINT github_users_pkey PRIMARY KEY (id);


--
-- Name: knex_migrations_lock knex_migrations_lock_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1173,6 +1248,13 @@ CREATE TRIGGER set_updated_at_github_organizations BEFORE UPDATE ON public.githu
CREATE TRIGGER set_updated_at_github_repositories BEFORE UPDATE ON public.github_repositories FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: github_users set_updated_at_github_users; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER set_updated_at_github_users BEFORE UPDATE ON public.github_users FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: ossf_scorecard_results set_updated_at_ossf_scorecard_results; Type: TRIGGER; Schema: public; Owner: -
--
Expand Down
Loading