Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/database/migrations/0001-create-canonical_fields.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
create table canonical_fields (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
label varchar not null,
short_code varchar not null,
field_type varchar not null
);

comment on table canonical_fields is
Comment thread
slifty marked this conversation as resolved.
'Canonical fields are those fields that are unique across organizations.';
comment on column canonical_fields.label is 'The description of the field';
comment on column canonical_fields.short_code is 'The short name of the field';
comment on column canonical_fields.field_type is 'The data type of the field';
11 changes: 11 additions & 0 deletions src/database/migrations/0002-create-applicants.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table applicants (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
external_id varchar not null,
opted_in boolean not null default false
);

comment on table applicants is
'Applicants submit applications for (funding) opportunities.';
comment on column applicants.external_id is
'The external identifier, not necessarily unique across organizations.';
10 changes: 10 additions & 0 deletions src/database/migrations/0003-create-opportunities.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create table opportunities (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
title varchar not null
);

comment on table opportunities is
'Funding opportunities such as available grants or awards.';
comment on column opportunities.title is
'The external identifier; not necessarily unique across organizations.';
11 changes: 11 additions & 0 deletions src/database/migrations/0004-create-application_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table application_schemas (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
opportunity_id bigint not null
references opportunities (id) on delete cascade,
version smallint not null generated by default as identity,
constraint unique_opportunity_id_version unique (opportunity_id, version)
);

comment on table application_schemas is
'A set of canonical fields for one opportunity.'
18 changes: 18 additions & 0 deletions src/database/migrations/0005-create-application_schema_fields.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
create table application_schema_fields (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
application_schema_id bigint not null
references application_schemas (id) on delete cascade,
canonical_field_id bigint not null
references canonical_fields (id) on delete cascade,
position int not null,
label varchar not null,
constraint unique_application_schema_id_canonical_field_id unique(application_schema_id, canonical_field_id)
);

comment on table application_schema_fields is
'An available field in an application schema.';
comment on column application_schema_fields.position is
'The relative order of this field within its application schema.';
comment on column application_schema_fields.label is
'The name of this field within its application schema. These may vary between application schemas, opportunities, or organizations but many of these may refer to one canonical field.';
11 changes: 11 additions & 0 deletions src/database/migrations/0006-create-applications.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table applications (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
opportunity_id bigint not null
references opportunities (id) on delete cascade,
applicant_id bigint not null
references applicants (id) on delete cascade
);

comment on table applications is
'A submission to an opportunity for funding.';
17 changes: 17 additions & 0 deletions src/database/migrations/0007-create-application_versions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
create table application_versions (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
application_id bigint not null
references applications (id) on delete cascade,
application_schema_id bigint not null
references application_schemas (id) on delete cascade,
version int not null,
constraint unique_application_id_version unique (application_id, version)
);

comment on table application_versions is
'One instance or version of a filled-out application.';
comment on column application_versions.application_schema_id is
'The application schema for which this application was filled out.';
comment on column application_versions.version is
'When there are updates to an application, higher versions are used.';
17 changes: 17 additions & 0 deletions src/database/migrations/0008-create-application_field_values.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
create table application_field_values (
id bigint primary key generated always as identity,
created_at timestamp with time zone not null default now(),
application_version_id bigint not null
references application_versions (id) on delete cascade,
application_schema_field_id bigint not null
references application_schema_fields (id) on delete cascade,
position int not null default 0,
field_value varchar not null,
constraint unique_application_version_id_application_schema_field_id_position
unique(application_version_id, application_schema_field_id, position)
);

comment on table application_field_values is
'A filled-out field value in an application.';
comment on column application_field_values.position is
'When a field allows multiple responses, use additional position values.';