diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/controllers/BallotSelectionTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/controllers/BallotSelectionTest.java index cdf6dee5..0998ba1b 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/controllers/BallotSelectionTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/controllers/BallotSelectionTest.java @@ -31,56 +31,15 @@ import org.hibernate.Session; import us.freeandfair.corla.query.CastVoteRecordQueries; import us.freeandfair.corla.query.Setup; +import us.freeandfair.corla.util.TestClassWithDatabase; @Test(groups = {"integration"}) -public class BallotSelectionTest { +public class BallotSelectionTest extends TestClassWithDatabase { private BallotSelectionTest() {}; private Boolean return_cvr = true; - /** - * Container for the mock-up database. - */ - static PostgreSQLContainer postgres - = new PostgreSQLContainer<>("postgres:15-alpine") - // None of these actually have to be the same as the real database (except its name), but this - // makes it easy to match the setup scripts. - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - // .withInitScripts("corlaInit.sql","contest.sql"); - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - Persistence.beginTransaction(); - - } - - @AfterClass - public static void afterAll() { - postgres.stop(); - } - - @BeforeMethod - public static void beforeEach() { - Persistence.beginTransaction(); - } - - @AfterMethod - public static void afterEach() { - Persistence.rollbackTransaction(); - } - @Test() public void testAuditedPrefixLengthWithNone() { List cvrIds = new ArrayList<>(); diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/endpoint/StartAuditRoundTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/endpoint/StartAuditRoundTest.java index 7801265d..b645ff0d 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/endpoint/StartAuditRoundTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/endpoint/StartAuditRoundTest.java @@ -10,54 +10,14 @@ import us.freeandfair.corla.model.CountyDashboard; import us.freeandfair.corla.persistence.Persistence; import us.freeandfair.corla.query.Setup; +import us.freeandfair.corla.util.TestClassWithDatabase; import java.util.Properties; @Test(groups = {"integration"}) -public class StartAuditRoundTest { +public class StartAuditRoundTest extends TestClassWithDatabase { private StartAuditRoundTest() {}; - /** - * Container for the mock-up database. - */ - static PostgreSQLContainer postgres - = new PostgreSQLContainer<>("postgres:15-alpine") - // None of these actually have to be the same as the real database (except its name), but this - // makes it easy to match the setup scripts. - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - // .withInitScripts("corlaInit.sql","contest.sql"); - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - Persistence.beginTransaction(); - - } - - @AfterClass - public static void afterAll() { - postgres.stop(); - } - - @BeforeMethod - public static void beforeEach() { - Persistence.beginTransaction(); - } - - @AfterMethod - public static void afterEach() { - Persistence.rollbackTransaction(); - } // this test doesn't do much yet @Test() diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/AdministratorQueriesTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/AdministratorQueriesTest.java index 84307d94..241ee9c0 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/AdministratorQueriesTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/AdministratorQueriesTest.java @@ -5,6 +5,7 @@ import us.freeandfair.corla.model.Administrator; import us.freeandfair.corla.model.County; import us.freeandfair.corla.persistence.Persistence; +import us.freeandfair.corla.util.TestClassWithDatabase; import java.util.Properties; @@ -12,42 +13,7 @@ import static org.testng.AssertJUnit.assertNull; @Test -public class AdministratorQueriesTest { - - /** - * Container for the mock-up database. - */ - private static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:15-alpine") - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - } - @BeforeMethod - public static void beforeEach() { - Persistence.beginTransaction(); - } - - @AfterMethod - public static void afterEach() { - Persistence.rollbackTransaction(); - } - - @AfterClass - public static void afterall() { - postgres.stop(); - } +public class AdministratorQueriesTest extends TestClassWithDatabase { @Test public void testByUsernameState() { diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/BallotManifestInfoQueriesTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/BallotManifestInfoQueriesTest.java index 6886749c..c51a0812 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/BallotManifestInfoQueriesTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/BallotManifestInfoQueriesTest.java @@ -6,6 +6,7 @@ import org.testng.annotations.*; import us.freeandfair.corla.model.*; import us.freeandfair.corla.persistence.Persistence; +import us.freeandfair.corla.util.TestClassWithDatabase; import javax.swing.text.html.Option; import java.util.*; @@ -14,42 +15,7 @@ import static org.testng.AssertJUnit.assertEquals; @Test -public class BallotManifestInfoQueriesTest { - - /** - * Container for the mock-up database. - */ - private static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:15-alpine") - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - } - @BeforeMethod - public static void beforeEach() { - Persistence.beginTransaction(); - } - - @AfterMethod - public static void afterEach() { - Persistence.rollbackTransaction(); - } - - @AfterClass - public static void afterall() { - postgres.stop(); - } +public class BallotManifestInfoQueriesTest extends TestClassWithDatabase { public BallotManifestInfo setupBMI() { return new BallotManifestInfo(1L, diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/CastVoteRecordQueriesTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/CastVoteRecordQueriesTest.java index 042fb256..d2e26ee1 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/CastVoteRecordQueriesTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/CastVoteRecordQueriesTest.java @@ -23,48 +23,10 @@ import us.freeandfair.corla.model.*; import us.freeandfair.corla.persistence.Persistence; import us.freeandfair.corla.query.Setup; +import us.freeandfair.corla.util.TestClassWithDatabase; @Test(groups = {"integration"}) -public class CastVoteRecordQueriesTest { - - /** - * Container for the mock-up database. - */ - private static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:15-alpine") - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - } - @BeforeMethod - public static void beforeEach() { - Persistence.beginTransaction(); - } - - @AfterMethod - public static void afterEach() { - try { - Persistence.rollbackTransaction(); - } catch (IllegalStateException e) { - // Sometimes our tests intentionally kill the DB. - } - } - - @AfterClass - public static void afterall() { - postgres.stop(); - } +public class CastVoteRecordQueriesTest extends TestClassWithDatabase { public List noisyContestSetup(){ return noisyContestSetup(1L); diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestQueriesTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestQueriesTest.java index 7a79e592..504ba437 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestQueriesTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestQueriesTest.java @@ -8,6 +8,7 @@ import us.freeandfair.corla.model.*; import us.freeandfair.corla.model.Choice; import us.freeandfair.corla.persistence.Persistence; +import us.freeandfair.corla.util.TestClassWithDatabase; import java.awt.*; import java.util.*; @@ -16,42 +17,7 @@ import static org.testng.Assert.*; @Test(groups = {"integration"}) -public class ContestQueriesTest { - - /** - * Container for the mock-up database. - */ - private static PostgreSQLContainer postgres = new PostgreSQLContainer<>("postgres:15-alpine") - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - } - @BeforeMethod - public static void beforeEach() { - Persistence.beginTransaction(); - } - - @AfterMethod - public static void afterEach() { - Persistence.rollbackTransaction(); - } - - @AfterClass - public static void afterall() { - postgres.stop(); - } +public class ContestQueriesTest extends TestClassWithDatabase { public County countySetup() { return countySetup(1L); @@ -158,7 +124,7 @@ public void testForCountyNull() { } - @Test + @Test() public void testDBError() { // Close the database Persistence.commitTransaction(); diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestResultQueriesTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestResultQueriesTest.java index 15bff298..963cc926 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestResultQueriesTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ContestResultQueriesTest.java @@ -14,49 +14,10 @@ import us.freeandfair.corla.model.ContestResult; import us.freeandfair.corla.model.Contest; import us.freeandfair.corla.model.County; +import us.freeandfair.corla.util.TestClassWithDatabase; @Test(groups = {"integration"}) -public class ContestResultQueriesTest { - - /** - * Container for the mock-up database. - */ - static PostgreSQLContainer postgres - = new PostgreSQLContainer<>("postgres:15-alpine") - // None of these actually have to be the same as the real database (except its name), but this - // makes it easy to match the setup scripts. - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - // .withInitScripts("corlaInit.sql","contest.sql"); - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - - } - - @AfterClass - public static void afterAll() { - postgres.stop(); - } - - @BeforeMethod - public static void beforeEach() { - Persistence.beginTransaction(); - } - - @AfterMethod - public static void afterEach() { Persistence.rollbackTransaction(); } - +public class ContestResultQueriesTest extends TestClassWithDatabase { @Test() public void findOrCreateTest() { diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ExportQueriesTest.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ExportQueriesTest.java index 2d10a145..2c02f183 100644 --- a/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ExportQueriesTest.java +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/query/ExportQueriesTest.java @@ -4,67 +4,27 @@ import java.util.*; -import org.junit.Ignore; import org.testcontainers.containers.PostgreSQLContainer; import org.testng.annotations.*; import static org.testng.Assert.*; import us.freeandfair.corla.persistence.Persistence; -import us.freeandfair.corla.query.Setup; -import us.freeandfair.corla.query.ExportQueries; - -import org.hibernate.Session; -import org.hibernate.query.Query; -@Test(groups = {"integration"}) -public class ExportQueriesTest { - - /** - * Container for the mock-up database. - */ - static PostgreSQLContainer postgres - = new PostgreSQLContainer<>("postgres:15-alpine") - // None of these actually have to be the same as the real database (except its name), but this - // makes it easy to match the setup scripts. - .withDatabaseName("corla") - .withUsername("corlaadmin") - .withPassword("corlasecret") - // .withInitScripts("corlaInit.sql","contest.sql"); - .withInitScript("SQL/corlaInitEmpty.sql"); - - @BeforeClass - public static void beforeAll() { - postgres.start(); - Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); - hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); - hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); - hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); - hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); - Persistence.setProperties(hibernateProperties); - Persistence.beginTransaction(); +import org.hibernate.Session; +import us.freeandfair.corla.util.TestClassWithDatabase; - } - @AfterClass - public static void afterAll() { - postgres.stop(); - } +@Test(groups = {"integration"}) +public class ExportQueriesTest extends TestClassWithDatabase { @BeforeMethod public static void beforeEach() { - Persistence.beginTransaction(); insertSeed(); } - @AfterMethod - public static void afterEach() { - Persistence.rollbackTransaction(); - } - private static void insertSeed() { final Session s = Persistence.currentSession(); String query = "insert into dos_dashboard (id,seed) values (99,'1234');"; diff --git a/server/eclipse-project/src/test/java/us/freeandfair/corla/util/TestClassWithDatabase.java b/server/eclipse-project/src/test/java/us/freeandfair/corla/util/TestClassWithDatabase.java new file mode 100644 index 00000000..a3c8ae94 --- /dev/null +++ b/server/eclipse-project/src/test/java/us/freeandfair/corla/util/TestClassWithDatabase.java @@ -0,0 +1,109 @@ +/* +Democracy Developers IRV extensions to colorado-rla. + +@copyright 2024 Colorado Department of State + +These IRV extensions are designed to connect to a running instance of the raire +service (https://github.com/DemocracyDevelopers/raire-service), in order to +generate assertions that can be audited using colorado-rla. + +The colorado-rla IRV extensions are free software: you can redistribute it and/or modify it under the terms +of the GNU Affero General Public License as published by the Free Software Foundation, either +version 3 of the License, or (at your option) any later version. + +The colorado-rla IRV extensions are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License along with +raire-service. If not, see . +*/ + +package us.freeandfair.corla.util; + +import java.util.Properties; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import us.freeandfair.corla.persistence.Persistence; + +/** + * This class is designed to be extended by any test class that needs to interact with a test + * instantiation of the colorado-rla database. It provides convenience methods for instantiating + * a postgres container (initialised with one a given SQL script) and hibernate properties. + */ +public abstract class TestClassWithDatabase { + + + /** + * Container for the mock-up database. + */ + static PostgreSQLContainer postgres = createTestContainer(); + + + @BeforeClass + public static void beforeAll() { + postgres.start(); + Persistence.setProperties(createHibernateProperties(postgres)); + } + + @AfterClass + public static void afterAll() { + postgres.stop(); + } + + /** + * Begin a new transaction before each test method in the class is run. + */ + @BeforeMethod + public static void beforeTest(){ + Persistence.beginTransaction(); + } + + /** + * Rollback any changes to the (test) database after each test method is run. + */ + @AfterMethod + public static void afterTest(){ + try { + Persistence.rollbackTransaction(); + } catch (Exception ignored) { + } + } + + /** + * Create and return a postgres test container for the purposes of testing functionality that + * interacts with the database. + * @return a postgres test container representing a test database. + */ + public static PostgreSQLContainer createTestContainer() { + return new PostgreSQLContainer<>("postgres:15-alpine") + // None of these actually have to be the same as the real database (except its name), + // but this makes it easy to match the setup scripts. + // .withExposedPorts(port) + .withDatabaseName("corla") + .withUsername("corlaadmin") + .withPassword("corlasecret") + .withInitScript("SQL/corla.sql"); + } + + /** + * Create and return a hibernate properties object for use in testing functionality that + * interacts with the database. + * @param postgres Postgres test container representing a test version of the database. + * @return Hibernate persistence properties. + */ + public static Properties createHibernateProperties(PostgreSQLContainer postgres) { + Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.driver", "org.postgresql.Driver"); + hibernateProperties.setProperty("hibernate.url", postgres.getJdbcUrl()); + hibernateProperties.setProperty("hibernate.user", postgres.getUsername()); + hibernateProperties.setProperty("hibernate.pass", postgres.getPassword()); + hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL9Dialect"); + + return hibernateProperties; + } + +} \ No newline at end of file diff --git a/server/eclipse-project/src/test/resources/SQL/corla.sql b/server/eclipse-project/src/test/resources/SQL/corla.sql new file mode 100644 index 00000000..24b5f7eb --- /dev/null +++ b/server/eclipse-project/src/test/resources/SQL/corla.sql @@ -0,0 +1,737 @@ +create table asm_state +( + id bigint not null + primary key, + asm_class varchar(255) not null, + asm_identity varchar(255), + state_class varchar(255), + state_value varchar(255), + version bigint +); + +alter table asm_state + owner to corlaadmin; + +create table assertion +( + assertion_type varchar(31) not null, + id bigserial + primary key, + contest_name varchar(255) not null, + current_risk numeric(19, 2) not null, + difficulty double precision not null, + diluted_margin numeric(19, 2) not null, + estimated_samples_to_audit integer not null, + loser varchar(255) not null, + margin integer not null, + one_vote_over_count integer not null, + one_vote_under_count integer not null, + optimistic_samples_to_audit integer not null, + other_count integer not null, + two_vote_over_count integer not null, + two_vote_under_count integer not null, + version bigint, + winner varchar(255) not null +); + +alter table assertion + owner to corlaadmin; + +create table assertion_assumed_continuing +( + id bigint not null + constraint fki0lyp4tghtpohaa9ma6kv2174 + references assertion, + assumed_continuing varchar(255) not null +); + +alter table assertion_assumed_continuing + owner to corlaadmin; + +create table assertion_discrepancies +( + id bigint not null + constraint fkt31yi3mf6c9axmt1gn1mu33ea + references assertion, + discrepancy integer not null, + cvr_id bigint not null, + primary key (id, cvr_id) +); + +alter table assertion_discrepancies + owner to corlaadmin; + +create table ballot_manifest_info +( + id bigint not null + primary key, + batch_id varchar(255) not null, + batch_size integer not null, + county_id bigint not null, + scanner_id integer not null, + sequence_end bigint not null, + sequence_start bigint not null, + storage_location varchar(255) not null, + version bigint, + ultimate_sequence_end bigint, + ultimate_sequence_start bigint, + uri varchar(255) +); + +alter table ballot_manifest_info + owner to corlaadmin; + +create index idx_bmi_county + on ballot_manifest_info (county_id); + +create index idx_bmi_seqs + on ballot_manifest_info (sequence_start, sequence_end); + +create table cast_vote_record +( + id bigint not null + primary key, + audit_board_index integer, + comment varchar(255), + cvr_id bigint, + ballot_type varchar(255) not null, + batch_id varchar(255) not null, + county_id bigint not null, + cvr_number integer not null, + imprinted_id varchar(255) not null, + record_id integer not null, + record_type varchar(255) not null, + scanner_id integer not null, + sequence_number integer, + timestamp timestamp, + version bigint, + rand integer, + revision bigint, + round_number integer, + uri varchar(255), + constraint uniquecvr + unique (county_id, imprinted_id, record_type, revision) +); + +alter table cast_vote_record + owner to corlaadmin; + +create index idx_cvr_county_type + on cast_vote_record (county_id, record_type); + +create index idx_cvr_county_cvr_number + on cast_vote_record (county_id, cvr_number); + +create index idx_cvr_county_cvr_number_type + on cast_vote_record (county_id, cvr_number, record_type); + +create index idx_cvr_county_sequence_number_type + on cast_vote_record (county_id, sequence_number, record_type); + +create index idx_cvr_county_imprinted_id_type + on cast_vote_record (county_id, imprinted_id, record_type); + +create index idx_cvr_uri + on cast_vote_record (uri); + +create table contest_result +( + id bigint not null + primary key, + audit_reason integer, + ballot_count bigint, + contest_name varchar(255) not null + constraint idx_cr_contest + unique, + diluted_margin numeric(19, 2), + losers text, + max_margin integer, + min_margin integer, + version bigint, + winners text, + winners_allowed integer +); + +alter table contest_result + owner to corlaadmin; + +create table comparison_audit +( + audit_type varchar(31) not null, + id bigint not null + primary key, + contest_cvr_ids text, + diluted_margin numeric(10, 8) not null, + audit_reason varchar(255) not null, + audit_status varchar(255) not null, + audited_sample_count integer not null, + disagreement_count integer not null, + estimated_recalculate_needed boolean not null, + estimated_samples_to_audit integer not null, + gamma numeric(10, 8) not null, + one_vote_over_count integer not null, + one_vote_under_count integer not null, + optimistic_recalculate_needed boolean not null, + optimistic_samples_to_audit integer not null, + other_count integer not null, + risk_limit numeric(10, 8) not null, + two_vote_over_count integer not null, + two_vote_under_count integer not null, + version bigint, + overstatements numeric(19, 2), + contest_result_id bigint not null + constraint fkn14qkca2ilirtpr4xctw960pe + references contest_result +); + +alter table comparison_audit + owner to corlaadmin; + +create table audit_to_assertions +( + id bigint not null + constraint fkgrx2l2qywbc3nv83iid55ql36 + references comparison_audit, + assertions_id bigint not null + constraint fkqomhyyib2xno6nq0wjpv95fs5 + references assertion +); + +alter table audit_to_assertions + owner to corlaadmin; + +create table contest_vote_total +( + result_id bigint not null + constraint fkfjk25vmtng6dv2ejlp8eopy34 + references contest_result, + vote_total integer, + choice varchar(255) not null, + primary key (result_id, choice) +); + +alter table contest_vote_total + owner to corlaadmin; + +create table county +( + id bigint not null + primary key, + name varchar(255) not null + constraint uk_npkepig28dujo4w98bkmaclhp + unique, + version bigint +); + +alter table county + owner to corlaadmin; + +create table administrator +( + id bigint not null + primary key, + full_name varchar(255) not null, + last_login_time timestamp, + last_logout_time timestamp, + type varchar(255) not null, + username varchar(255) not null + constraint uk_esogmqxeek1uwdyhxvubme3qf + unique, + version bigint, + county_id bigint + constraint fkh6rcfib1ishmhry9ctgm16gie + references county +); + +alter table administrator + owner to corlaadmin; + +create table contest +( + id bigint not null + primary key, + description varchar(255) not null, + name varchar(255) not null, + sequence_number integer not null, + version bigint, + votes_allowed integer not null, + winners_allowed integer not null, + county_id bigint not null + constraint fk932jeyl0hqd21fmakkco5tfa3 + references county, + constraint ukdv45ptogm326acwp45hm46uaf + unique (name, county_id, description, votes_allowed) +); + +alter table contest + owner to corlaadmin; + +create index idx_contest_name + on contest (name); + +create index idx_contest_name_county_description_votes_allowed + on contest (name, county_id, description, votes_allowed); + +create table contest_choice +( + contest_id bigint not null + constraint fknsr30axyiavqhyupxohtfy0sl + references contest, + description varchar(255), + fictitious boolean not null, + name varchar(255), + qualified_write_in boolean not null, + index integer not null, + primary key (contest_id, index), + constraint uka8o6q5yeepuy2cgnrbx3l1rka + unique (contest_id, name) +); + +alter table contest_choice + owner to corlaadmin; + +create table contests_to_contest_results +( + contest_result_id bigint not null + constraint fkr1jgmnxu2fbbvujdh3srjmot9 + references contest_result, + contest_id bigint not null + constraint uk_t1qahmm5y32ovxtqxne8i7ou0 + unique + constraint fki7qed7v0pkbi2bnd5fvujtp7 + references contest, + primary key (contest_result_id, contest_id) +); + +alter table contests_to_contest_results + owner to corlaadmin; + +create table counties_to_contest_results +( + contest_result_id bigint not null + constraint fk2h2muw290os109yqar5p4onms + references contest_result, + county_id bigint not null + constraint fk1ke574b6yqdc8ylu5xyqrounp + references county, + primary key (contest_result_id, county_id) +); + +alter table counties_to_contest_results + owner to corlaadmin; + +create table county_contest_result +( + id bigint not null + primary key, + contest_ballot_count integer, + county_ballot_count integer, + losers text, + max_margin integer, + min_margin integer, + version bigint, + winners text, + winners_allowed integer not null, + contest_id bigint not null + constraint fkon2wldpt0279jqex3pjx1mhm7 + references contest, + county_id bigint not null + constraint fkcuw4fb39imk9pyw360bixorm3 + references county, + constraint idx_ccr_county_contest + unique (county_id, contest_id) +); + +alter table county_contest_result + owner to corlaadmin; + +create index idx_ccr_county + on county_contest_result (county_id); + +create index idx_ccr_contest + on county_contest_result (contest_id); + +create table county_contest_vote_total +( + result_id bigint not null + constraint fkip5dfccmp5x5ubssgar17qpwk + references county_contest_result, + vote_total integer, + choice varchar(255) not null, + primary key (result_id, choice) +); + +alter table county_contest_vote_total + owner to corlaadmin; + +create table cvr_audit_info +( + id bigint not null + primary key, + count_by_contest text, + multiplicity_by_contest text, + disagreement text not null, + discrepancy text not null, + version bigint, + acvr_id bigint + constraint fk2n0rxgwa4njtnsm8l4hwc8khy + references cast_vote_record, + cvr_id bigint not null + constraint fkdks3q3g0srpa44rkkoj3ilve6 + references cast_vote_record +); + +alter table cvr_audit_info + owner to corlaadmin; + +create table contest_comparison_audit_disagreement +( + contest_comparison_audit_id bigint not null + constraint fkt490by57jb58ubropwn7kmadi + references comparison_audit, + cvr_audit_info_id bigint not null + constraint fkpfdns930t0qv905vbwhgcxnl2 + references cvr_audit_info, + primary key (contest_comparison_audit_id, cvr_audit_info_id) +); + +alter table contest_comparison_audit_disagreement + owner to corlaadmin; + +create table contest_comparison_audit_discrepancy +( + contest_comparison_audit_id bigint not null + constraint fkcajmftu1xv4jehnm5qhc35j9n + references comparison_audit, + discrepancy integer, + cvr_audit_info_id bigint not null + constraint fk3la5frd86i29mlwjd8akjgpwp + references cvr_audit_info, + primary key (contest_comparison_audit_id, cvr_audit_info_id) +); + +alter table contest_comparison_audit_discrepancy + owner to corlaadmin; + +create table cvr_contest_info +( + cvr_id bigint not null + constraint fkrsovkqe4e839e0aels78u7a3g + references cast_vote_record, + county_id bigint, + choices varchar(1024), + comment varchar(255), + consensus varchar(255), + contest_id bigint not null + constraint fke2fqsfmj0uqq311l4c3i0nt7r + references contest, + index integer not null, + primary key (cvr_id, index) +); + +alter table cvr_contest_info + owner to corlaadmin; + +create index idx_cvrci_uri + on cvr_contest_info (county_id, contest_id); + +create table dos_dashboard +( + id bigint not null + primary key, + canonical_choices text, + canonical_contests text, + election_date timestamp, + election_type varchar(255), + public_meeting_date timestamp, + risk_limit numeric(10, 8), + seed varchar(255), + version bigint +); + +alter table dos_dashboard + owner to corlaadmin; + +create table contest_to_audit +( + dashboard_id bigint not null + constraint fkjlw9bpyarqou0j26hq7mmq8qm + references dos_dashboard, + audit varchar(255), + contest_id bigint not null + constraint fkid09bdp5ifs6m4cnyw3ycyo1s + references contest, + reason varchar(255) +); + +alter table contest_to_audit + owner to corlaadmin; + +create table log +( + id bigint not null + primary key, + authentication_data varchar(255), + client_host varchar(255), + hash varchar(255) not null, + information varchar(255) not null, + result_code integer, + timestamp timestamp not null, + version bigint, + previous_entry bigint + constraint fkfw6ikly73lha9g9em13n3kat4 + references log +); + +alter table log + owner to corlaadmin; + +create table tribute +( + id bigint not null + primary key, + ballot_position integer, + batch_id varchar(255), + contest_name varchar(255), + county_id bigint, + rand integer, + rand_sequence_position integer, + scanner_id integer, + uri varchar(255), + version bigint +); + +alter table tribute + owner to corlaadmin; + +create table uploaded_file +( + id bigint not null + primary key, + computed_hash varchar(255) not null, + approximate_record_count integer not null, + file oid not null, + filename varchar(255), + size bigint not null, + timestamp timestamp not null, + version bigint, + result text, + status varchar(255) not null, + submitted_hash varchar(255) not null, + county_id bigint not null + constraint fk8gh92iwaes042cc1uvi6714yj + references county +); + +alter table uploaded_file + owner to corlaadmin; + +create table county_dashboard +( + id bigint not null + primary key, + audit_board_count integer, + driving_contests text, + audit_timestamp timestamp, + audited_prefix_length integer, + audited_sample_count integer, + ballots_audited integer not null, + ballots_in_manifest integer not null, + current_round_index integer, + cvr_import_error_message varchar(255), + cvr_import_state varchar(255), + cvr_import_timestamp timestamp, + cvrs_imported integer not null, + disagreements text not null, + discrepancies text not null, + version bigint, + county_id bigint not null + constraint uk_6lcjowb4rw9xav8nqnf5v2klk + unique + constraint fk1bg939xcuwen7fohfkdx10ueb + references county, + cvr_file_id bigint + constraint fk6rb04heyw700ep1ynn0r31xv3 + references uploaded_file, + manifest_file_id bigint + constraint fkrs4q3gwfv0up7swx7q1q6xlwo + references uploaded_file +); + +alter table county_dashboard + owner to corlaadmin; + +create table audit_board +( + dashboard_id bigint not null + constraint fkai07es6t6bdw8hidapxxa5xnp + references county_dashboard, + members text, + sign_in_time timestamp not null, + sign_out_time timestamp, + index integer not null, + primary key (dashboard_id, index) +); + +alter table audit_board + owner to corlaadmin; + +create table audit_intermediate_report +( + dashboard_id bigint not null + constraint fkmvj30ou8ik3u7avvycsw0vjx8 + references county_dashboard, + report varchar(255), + timestamp timestamp, + index integer not null, + primary key (dashboard_id, index) +); + +alter table audit_intermediate_report + owner to corlaadmin; + +create table audit_investigation_report +( + dashboard_id bigint not null + constraint fkdox65w3y11hyhtcba5hrekq9u + references county_dashboard, + name varchar(255), + report varchar(255), + timestamp timestamp, + index integer not null, + primary key (dashboard_id, index) +); + +alter table audit_investigation_report + owner to corlaadmin; + +create table county_contest_comparison_audit +( + id bigint not null + primary key, + diluted_margin numeric(10, 8) not null, + audit_reason varchar(255) not null, + audit_status varchar(255) not null, + audited_sample_count integer not null, + disagreement_count integer not null, + estimated_recalculate_needed boolean not null, + estimated_samples_to_audit integer not null, + gamma numeric(10, 8) not null, + one_vote_over_count integer not null, + one_vote_under_count integer not null, + optimistic_recalculate_needed boolean not null, + optimistic_samples_to_audit integer not null, + other_count integer not null, + risk_limit numeric(10, 8) not null, + two_vote_over_count integer not null, + two_vote_under_count integer not null, + version bigint, + contest_id bigint not null + constraint fk8te9gv7q10wxbhg5pgttbj3mv + references contest, + contest_result_id bigint not null + constraint fkag9u8fyqni2ehb2dtqop4pox8 + references contest_result, + dashboard_id bigint not null + constraint fksycb9uto400qabgb97d4ihbat + references county_dashboard +); + +alter table county_contest_comparison_audit + owner to corlaadmin; + +create index idx_ccca_dashboard + on county_contest_comparison_audit (dashboard_id); + +create table county_contest_comparison_audit_disagreement +( + county_contest_comparison_audit_id bigint not null + constraint fk7yt9a4fjcdctwmftwwsksdnma + references county_contest_comparison_audit, + cvr_audit_info_id bigint not null + constraint fk9lhehe4o2dgqde06pxycydlu6 + references cvr_audit_info, + primary key (county_contest_comparison_audit_id, cvr_audit_info_id) +); + +alter table county_contest_comparison_audit_disagreement + owner to corlaadmin; + +create table county_contest_comparison_audit_discrepancy +( + county_contest_comparison_audit_id bigint not null + constraint fk39q8rjoa19c4fdjmv4m9iir06 + references county_contest_comparison_audit, + discrepancy integer, + cvr_audit_info_id bigint not null + constraint fkpe25737bc4mpt170y53ba7il2 + references cvr_audit_info, + primary key (county_contest_comparison_audit_id, cvr_audit_info_id) +); + +alter table county_contest_comparison_audit_discrepancy + owner to corlaadmin; + +create table county_dashboard_to_comparison_audit +( + dashboard_id bigint not null + constraint fkds9j4o8el1f4nepf2677hvs5o + references county_dashboard, + comparison_audit_id bigint not null + constraint fksliko6ckjcr7wvmicuqyreopl + references comparison_audit, + primary key (dashboard_id, comparison_audit_id) +); + +alter table county_dashboard_to_comparison_audit + owner to corlaadmin; + +create table round +( + dashboard_id bigint not null + constraint fke3kvxe5r43a4xmeugp8lnme9e + references county_dashboard, + ballot_sequence_assignment text not null, + actual_audited_prefix_length integer, + actual_count integer not null, + audit_subsequence text not null, + ballot_sequence text not null, + disagreements text not null, + discrepancies text not null, + end_time timestamp, + expected_audited_prefix_length integer not null, + expected_count integer not null, + number integer not null, + previous_ballots_audited integer not null, + signatories text, + start_audited_prefix_length integer not null, + start_time timestamp not null, + index integer not null, + primary key (dashboard_id, index) +); + +alter table round + owner to corlaadmin; + +create index idx_uploaded_file_county + on uploaded_file (county_id); + +-- +-- Name: hibernate_sequence; Type: SEQUENCE; Schema: public; Owner: corlaadmin +-- + +CREATE SEQUENCE public.hibernate_sequence + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.hibernate_sequence OWNER TO corlaadmin; + +-- +-- Name: hibernate_sequence; Type: SEQUENCE SET; Schema: public; Owner: corlaadmin +-- + +SELECT pg_catalog.setval('public.hibernate_sequence', 44767, true); \ No newline at end of file