diff --git a/.gitignore b/.gitignore index 111114d2..6e374e77 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ npm-debug.log *~ conf/generated.keystore +conf/evolutions __pycache__/ diff --git a/README.md b/README.md index fd67a46a..e134eb34 100644 --- a/README.md +++ b/README.md @@ -5,29 +5,44 @@ for [Sudbury](https://en.wikipedia.org/wiki/Sudbury_school)-inspired schools. In addition, it does a satisfactory job of tracking people (students, parents, donors, and others), student attendance, and the management manual. -## Documentation for users +# Documentation for users See [the wiki](https://github.com/schmave/demschooltools/wiki/) for more information. -## Running the site locally for development +# Running the site locally for development -[Download](https://github.com/schmave/demschooltools/archive/master.zip) the source code, or clone the git repository. `cd` into the root level of the source code. +## Installation -You'll need to run three separate programs for each of the parts of the site. - -### (1 of 3) Play Framework code +1. [Download](https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html) and install Oracle JDK version 11.x. Set the JAVA_HOME environment variable to be the location that you installed it, meaning that $JAVA_HOME/bin/java (or $JAVA_HOME/bin/java.exe on Windows) should be the path to the java binary. -1. [Download](https://openjdk.org/) and install OpenJDK version 11.x. Set the JAVA_HOME environment variable to be the location that you installed it, meaning that $JAVA_HOME/bin/java should be the path to the java binary. +1. Install [sbt 1.x](https://www.scala-sbt.org/download/). If you use a Mac, I recommend using [homebrew](https://brew.sh/) to install it. -1. Install [sbt 1.10](https://www.scala-sbt.org/download/). If you use a Mac, I recommend using [homebrew](https://brew.sh/) to install it. +1. [Download](http://www.postgresql.org/download/) and install PostgreSQL. If you use a Mac, I recommend installing the ["Postgres" app](https://postgresapp.com/) instead. -1. [Download](http://www.postgresql.org/download/) and install PostgreSQL. If you use a Mac, I recommend installing [the "Postgres" app](https://postgresapp.com/) instead. +1. [Download](https://nodejs.org/en/download/archive/v22) and install Node v22. If you use Mac or Linux or Windows WSL, I recommend using [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md#about) to download and install it instead of the Node website. -1. [Download](https://nodejs.org/en/download/releases/) and install Node v22. If you use Mac or Linux or Windows WSL, I recommend using [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md#about) to install it. +1. [Download](https://github.com/schmave/demschooltools/archive/master.zip) the source code, or clone the git repository. `cd` into the root level of the source code. 1. Run `npm install` to install the Javascript libraries. -1. Start PostgreSQL and create a database named "school_crm". You'll also need to set the password for the user named "postgres" to "123", or change the database username and password in [conf/base.conf](conf/base.conf) and [django/demschooltools/settings.py](django/demschooltools/settings.py). +1. Start the PostgreSQL server and create a database named "school_crm". You'll also need to set the password for the user named "postgres" to "123", or change the database username and password in [conf/base.conf](conf/base.conf) and [django/demschooltools/settings.py](django/demschooltools/settings.py). + +1. Install [uv](https://docs.astral.sh/uv/getting-started/installation/#standalone-installer). Once you run it, you'll need to close your terminal window and reopen it before continuing. + +1. Run: + + cd django + uv run manage.py migrate + uv run manage.py setup_initial_data + cd .. + + If you see errors when running `manage.py migrate`, [read below](#dealing-with-inconsistentmigrationhistory) for troubleshooting info. + +## Running the site + +You'll need to run three separate programs for each of the parts of the site. + +### (1 of 3) Play Framework code 1. Run `./sbt.sh`, then execute the `eclipse` and `run` command in the sbt console: @@ -39,47 +54,11 @@ You'll need to run three separate programs for each of the parts of the site. [info] modelsLibrary [DemSchoolTools] $ run -1. Navigate to [http://localhost:9000](http://localhost:9000) in your browser - and wait while DemSchoolTools is compiled. - -1. When it loads, you should see a message saying - "Database 'default' needs evolution!". Click "Apply this script now." If errors happen after you click "Apply this script now.", look in the "Play database evolutions troubleshooting" section below for advice. - -1. Wait until you see the message "Unknown organization" in your browser window. - -1. Connect to your Postgres database and run this SQL: - - ```sql - INSERT INTO organization_hosts(host, organization_id) - VALUES ('localhost:9000', 1); - INSERT INTO tag(title, use_student_display, organization_id, show_in_jc, show_in_attendance, show_in_account_balances, show_in_roles) - VALUES ('Current Student', true, 1, true, true, true, true); - INSERT INTO tag(title, use_student_display, organization_id, show_in_jc, show_in_attendance, show_in_account_balances, show_in_roles) - VALUES ('Staff', false, 1, true, true, true, true); - - INSERT INTO users(email, name, active, email_validated, - is_staff, is_superuser, hashed_password) - VALUES ('admin@asdf.com', 'Admin User', true, true, true, true, - '$2a$10$sHAtPc.yeZg2AWMr7EZZbuu.sYaOPgFsMZiAY62q/URbjMxU3jB.q'); - - INSERT INTO user_role (user_id, role) - SELECT id, 'all-access' from users; - - UPDATE organization set - show_custodia=true, show_accounting=true, - enable_case_references=true, show_electronic_signin=true, - show_roles=true; - ``` - -1. Reload [http://localhost:9000](http://localhost:9000). Login with Email `admin@asdf.com` and password `nopassword`. You will see - a page with headings "People", "Attendance", "JC", etc. - ### (2 of 3) Django code -The Django code uses [uv](https://docs.astral.sh/uv/) to manage its dependencies. I installed uv using using the standalone installer [described here](https://docs.astral.sh/uv/getting-started/installation/#standalone-installer). Once you run it, you'll need to close you terminal window and reopen it before continuing. - -Then run: +Run: + cd django uv run manage.py migrate uv run manage.py runserver @@ -91,47 +70,43 @@ To enable the Custodia attendance system locally, run: npm install npm run watch -# Play database evolutions troubleshooting +### Opening the site -### 64.sql +Once you have all three servers running, you can: -If 64.sql fails to apply with the error `role "custodia" already exists`, -do this: +1. Navigate to [http://localhost:9000](http://localhost:9000) in your browser + and wait while DemSchoolTools is compiled. -1. Run the remaining "up" lines from 64.sql: +1. Login with Email `admin@asdf.com` and password `nopassword`. -```sql -grant select on all tables in schema public to custodia; +## Dealing with "InconsistentMigrationHistory" -create schema if not exists overseer; -grant all on schema overseer to custodia; -grant all on all tables in schema overseer to custodia; -grant all on all sequences in schema overseer to custodia; +If you first set up your local development environment before November 2025, you will see this error when you run `uv run manage.py migrate`: -create schema if not exists demo; -grant all on schema demo to custodia; -grant all on all sequences in schema demo to custodia; -grant all on all tables in schema demo to custodia; +``` +django.db.migrations.exceptions.InconsistentMigrationHistory: + Migration admin.0001_initial is applied before its + dependency dst.0001_initial on database 'default'. ``` -2. Click "Mark it resolved". +If you're willing to discard your local data, then the easiest way to fix this is to delete your entire school_crm database and start fresh with the migrate and setup_initial_data installation step above. If you want to keep your data, read on. -### 102.sql +### Apply all old Play evolutions -If 102.sql fails to apply with the error `relation "custodia_swipe" does not exist`, do this: +First, you need to apply all Play schema changes that existed before they were deleted and replaced with Django ones. -1. Run these commands: +Run `git fetch; git checkout cadf15b712e4801fa6f1bfd9cd71f100a89b1519`, then run the Play server as described in "1 of 3" above, go to http://localhost:9000 and click "Apply this script now.". -``` -cd django -uv run manage.py migrate -``` +Then quit Play and sbt and run `git checkout main; git pull`. + +### Tell Django that the Django migrations have already been applied -2. Run the "up" line from 102.sql: +Connect to the school_crm database and run this SQL statement: ```sql -create unique index person_swipe_day_empty_out_unique - on custodia_swipe(person_id, swipe_day) WHERE out_time is null; +INSERT INTO django_migrations(app, name, applied) VALUES + ('dst', '0001_initial', clock_timestamp()), + ('custodia', '0003_swipe_person_swipe_day_empty_out_unique', clock_timestamp()); ``` -3. Click "Mark it resolved". +Then you should be able to run `uv run manage.py migrate` without errors. diff --git a/app/controllers/CRM.java b/app/controllers/CRM.java index 2f7e54d9..6cfd1778 100644 --- a/app/controllers/CRM.java +++ b/app/controllers/CRM.java @@ -280,6 +280,7 @@ public Result addTag(Integer tagId, String title, Integer personId, Http.Request Tag the_tag; if (tagId == null) { the_tag = Tag.create(title, org); + the_tag.refresh(); } else { the_tag = Tag.find.ref(tagId); } diff --git a/build.sbt b/build.sbt index a3a8bb4d..6d60fd8c 100644 --- a/build.sbt +++ b/build.sbt @@ -50,7 +50,6 @@ ThisBuild / Compile / playEbeanModels := Seq("models.*") libraryDependencies ++= Seq( javaJdbc, - evolutions, ehcache, guice, "org.postgresql" % "postgresql" % "42.5.4", diff --git a/conf/base.conf b/conf/base.conf index a46071b1..c3fa7c9b 100644 --- a/conf/base.conf +++ b/conf/base.conf @@ -43,8 +43,8 @@ ebean.default=["models.*"] # Evolutions # ~~~~~ -# You can disable evolutions if needed -# play.evolutions.enabled=false +# DB schema is handled by Django, not Play +play.evolutions.enabled=false # Rollbar # ~~~~~ diff --git a/conf/evolutions/default/1.sql b/conf/evolutions/default/1.sql deleted file mode 100644 index e2e3955e..00000000 --- a/conf/evolutions/default/1.sql +++ /dev/null @@ -1,32 +0,0 @@ -# --- !Ups - -create table person ( - person_id integer not null, - first_name varchar(255), - last_name varchar(255), - notes TEXT, - address varchar(255), - city varchar(255), - state varchar(255), - zip varchar(255), - neighborhood varchar(255), - email varchar(255), - dob timestamp, - approximate_dob timestamp, - is_family boolean, - family_person_id integer, - constraint pk_person primary key (person_id)) -; - -create sequence person_seq; - -alter table person add constraint fk_person_family_1 foreign key (family_person_id) references person (person_id); -create index ix_person_family_1 on person (family_person_id); - - - -# --- !Downs - -drop table if exists person cascade; - -drop sequence if exists person_seq; diff --git a/conf/evolutions/default/10.sql b/conf/evolutions/default/10.sql deleted file mode 100644 index f9c0fc66..00000000 --- a/conf/evolutions/default/10.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -alter table person add column gender varchar(10) not null default 'Unknown' - check(gender = 'Unknown' or gender='Male' or gender='Female'); - -# --- !Downs - -alter table person drop column gender; - diff --git a/conf/evolutions/default/100.sql b/conf/evolutions/default/100.sql deleted file mode 100644 index dc045c82..00000000 --- a/conf/evolutions/default/100.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_default_absence_code text; -ALTER TABLE organization ADD COLUMN attendance_default_absence_code_time time; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_default_absence_code; -ALTER TABLE organization DROP COLUMN attendance_default_absence_code_time; diff --git a/conf/evolutions/default/101.sql b/conf/evolutions/default/101.sql deleted file mode 100644 index 9ac5ebd3..00000000 --- a/conf/evolutions/default/101.sql +++ /dev/null @@ -1,35 +0,0 @@ - -# --- !Ups - --- Prepare for migrating custodia columns to DST -ALTER TABLE organization ADD COLUMN timezone varchar(255) DEFAULT 'America/New_York' NOT NULL; -ALTER TABLE organization ADD COLUMN late_time TIME DEFAULT '10:15:00'::time without time zone NULL; -ALTER TABLE organization ALTER COLUMN late_time DROP DEFAULT; -ALTER TABLE person ADD COLUMN custodia_show_as_absent date NULL; -ALTER TABLE person ADD COLUMN custodia_start_date date NULL; - ---- Add some columns for Django user stuff -ALTER TABLE users ADD COLUMN date_joined timestamptz NOT NULL default '2000-01-01'; -ALTER TABLE users ADD COLUMN last_login timestamptz NULL default NULL; -ALTER TABLE users ADD COLUMN first_name varchar(150) NOT NULL default ''; -ALTER TABLE users ADD COLUMN last_name varchar(150) NOT NULL default ''; -ALTER TABLE users ADD COLUMN is_superuser bool NOT NULL default false; -ALTER TABLE users ADD COLUMN is_staff bool NOT NULL default false; -ALTER TABLE users ADD COLUMN username varchar(150) NOT NULL default ''; - ---- Add primary keys where there were none -ALTER TABLE person_change ADD COLUMN id SERIAL PRIMARY KEY; -ALTER TABLE charge_reference ADD COLUMN id SERIAL PRIMARY KEY; -ALTER TABLE charge_reference ADD CONSTRAINT uk_charge_case UNIQUE (referenced_charge, referencing_case); -ALTER TABLE case_reference ADD COLUMN id SERIAL PRIMARY KEY; -ALTER TABLE case_reference ADD CONSTRAINT uk_case_case UNIQUE (referenced_case, referencing_case); -ALTER TABLE role_record_member ADD COLUMN id SERIAL PRIMARY KEY; - --- Add indexes where there should have been some -create index attendance_day_day_idx on attendance_day ("day"); -create index attendance_week_monday_idx on attendance_week ("monday"); - - -# --- !Downs - ---- There are no downs. \ No newline at end of file diff --git a/conf/evolutions/default/102.sql b/conf/evolutions/default/102.sql deleted file mode 100644 index 807dd1da..00000000 --- a/conf/evolutions/default/102.sql +++ /dev/null @@ -1,22 +0,0 @@ - -# --- !Ups - --- Run this to delete duplicates if needed - --- DELETE FROM custodia_swipe a USING ( --- SELECT MIN(ctid) as ctid, person_id, swipe_day --- FROM custodia_swipe --- WHERE out_time is null --- GROUP BY person_id, swipe_day HAVING COUNT(*) > 1 --- ) b --- WHERE a.person_id = b.person_id and a.swipe_day=b.swipe_day and out_time is null --- AND a.ctid <> b.ctid; - - -create unique index person_swipe_day_empty_out_unique on custodia_swipe(person_id, swipe_day) WHERE out_time is null; - - - -# --- !Downs - -drop index person_swipe_day_empty_out_unique; diff --git a/conf/evolutions/default/103.sql b/conf/evolutions/default/103.sql deleted file mode 100644 index 7858b602..00000000 --- a/conf/evolutions/default/103.sql +++ /dev/null @@ -1,10 +0,0 @@ - -# --- !Ups - - - -alter table manual_change alter column date_entered type timestamptz using date_entered at time zone 'UTC'; - -# --- !Downs - -alter table manual_change alter column date_entered type timestamp using date_entered at time zone 'UTC'; diff --git a/conf/evolutions/default/104.sql b/conf/evolutions/default/104.sql deleted file mode 100644 index 722e431a..00000000 --- a/conf/evolutions/default/104.sql +++ /dev/null @@ -1,13 +0,0 @@ -# --- !Ups - -alter table manual_change add column effective_date date NULL default NULL; -alter table manual_change add column user_id int default NULL; - -alter table manual_change add constraint fk_user_id foreign key (user_id) references users (id) on delete restrict on update restrict; - - -# --- !Downs - -alter table manual_change drop constraint fk_user_id; -alter table manual_change drop column user_id; -alter table manual_change drop column effective_date; diff --git a/conf/evolutions/default/105.sql b/conf/evolutions/default/105.sql deleted file mode 100644 index 3f197b80..00000000 --- a/conf/evolutions/default/105.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -alter table manual_change add column show_date_in_history boolean default true NOT NULL; - - -# --- !Downs - -alter table manual_change drop column show_date_in_history; diff --git a/conf/evolutions/default/106.sql b/conf/evolutions/default/106.sql deleted file mode 100644 index b4bed1da..00000000 --- a/conf/evolutions/default/106.sql +++ /dev/null @@ -1,6 +0,0 @@ -# --- !Ups - -DROP INDEX idx_entry_index; -DROP MATERIALIZED VIEW entry_index; - -# --- !Downs \ No newline at end of file diff --git a/conf/evolutions/default/107.sql b/conf/evolutions/default/107.sql deleted file mode 100644 index 7643e927..00000000 --- a/conf/evolutions/default/107.sql +++ /dev/null @@ -1,30 +0,0 @@ -# --- !Ups - -alter table public.account alter column date_last_monthly_credit type timestamptz; -alter table public.charge alter column rp_complete_date type timestamptz; - -alter table public.comments alter column created type timestamptz; -alter table public.comments alter column created set default now(); - -alter table public.donation alter column date type timestamptz; -alter table public.donation alter column date set default now(); - -alter table public.donation alter column thanked_time type timestamptz; -alter table public.donation alter column indiegogo_reward_given_time type timestamptz; - -alter table public.mailchimp_sync alter column last_sync type timestamptz; -alter table public.organization alter column mailchimp_last_sync_person_changes type timestamptz; - -alter table public.person alter column created type timestamptz; -alter table public.person alter column created set default now(); - -alter table public.person_change alter column "time" type timestamptz; -alter table public.person_change alter column "time" set default now(); - -alter table public.person_tag_change alter column "time" type timestamptz; -alter table public.person_tag_change alter column "time" set default now(); - -alter table public.role_record alter column date_created type timestamptz; -alter table public.transactions alter column date_created type timestamptz; - -# --- !Downs \ No newline at end of file diff --git a/conf/evolutions/default/11.sql b/conf/evolutions/default/11.sql deleted file mode 100644 index 7ca604ce..00000000 --- a/conf/evolutions/default/11.sql +++ /dev/null @@ -1,12 +0,0 @@ -# --- !Ups - -alter table person drop constraint person_gender_check; -alter table person add constraint person_gender_check - check(gender = 'Unknown' or gender='Male' or gender='Female' or gender='Other'); - -# --- !Downs - -alter table person drop constraint person_gender_check; -alter table person add constraint person_gender_check - check(gender = 'Unknown' or gender='Male' or gender='Female'); - diff --git a/conf/evolutions/default/12.sql b/conf/evolutions/default/12.sql deleted file mode 100644 index 78cc78a1..00000000 --- a/conf/evolutions/default/12.sql +++ /dev/null @@ -1,28 +0,0 @@ -# --- !Ups - -create table donation ( - id serial, - dollar_value float, - is_cash boolean not null, - description TEXT not null, - person_id integer not null, - date timestamp without time zone not null default now(), - - thanked boolean not null, - thanked_by_user_id integer default null, - thanked_time timestamp without time zone default null, - - indiegogo_reward_given boolean not null, - indiegogo_reward_by_user_id integer default null, - indiegogo_reward_given_time timestamp without time zone default null, - - constraint pk_donation primary key(id), - constraint fk_donation_person foreign key(person_id) references person(person_id) ON DELETE cascade ON UPDATE restrict, - - constraint fk_donation_user_1 foreign key(thanked_by_user_id) references users(id) on delete restrict on update restrict, - constraint fk_donation_user_2 foreign key(indiegogo_reward_by_user_id) references users(id) on delete restrict on update restrict -); - -# --- !Downs - -drop table donation; diff --git a/conf/evolutions/default/13.sql b/conf/evolutions/default/13.sql deleted file mode 100644 index 9d098337..00000000 --- a/conf/evolutions/default/13.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -alter table tag add column use_student_display boolean default false; - -# --- !Downs - -alter table tag drop column use_student_display; diff --git a/conf/evolutions/default/14.sql b/conf/evolutions/default/14.sql deleted file mode 100644 index 421f3dda..00000000 --- a/conf/evolutions/default/14.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -alter table task add column enabled boolean default true; - -# --- !Downs - -alter table task drop column enabled; diff --git a/conf/evolutions/default/15.sql b/conf/evolutions/default/15.sql deleted file mode 100644 index ea6d7d4d..00000000 --- a/conf/evolutions/default/15.sql +++ /dev/null @@ -1,10 +0,0 @@ -# --- !Ups - -alter table person add column previous_school character varying(255) default '' not null; -alter table person add column school_district character varying(255) default '' not null; - -# --- !Downs - -alter table person drop column previous_school; -alter table person drop column school_district; - diff --git a/conf/evolutions/default/16.sql b/conf/evolutions/default/16.sql deleted file mode 100644 index a43cbcfe..00000000 --- a/conf/evolutions/default/16.sql +++ /dev/null @@ -1,36 +0,0 @@ -# --- !Ups - -CREATE TABLE "case" - ( - case_number VARCHAR(255) NOT NULL DEFAULT '', - findings text, - DATE DATE, - constraint pk_case primary key (case_number) - ); - -CREATE TABLE rule - ( - id serial, - title VARCHAR(255) NOT NULL DEFAULT '', - constraint pk_rule primary key(id) - ); - -CREATE TABLE charge - ( - id serial, - case_id VARCHAR(255) NOT NULL DEFAULT '', - person_id int, - rule_id int, - plea VARCHAR(255) NOT NULL DEFAULT '', - resolution_plan text, - constraint pk_charge primary key (id), - constraint fk_charge_person foreign key (person_id) references person(person_id), - constraint fk_charge_rule foreign key (rule_id) references rule(id) - ); - - -# --- !Downs - -DROP TABLE "case"; -DROP TABLE charge; -DROP TABLE rule; diff --git a/conf/evolutions/default/17.sql b/conf/evolutions/default/17.sql deleted file mode 100644 index 72a36c2b..00000000 --- a/conf/evolutions/default/17.sql +++ /dev/null @@ -1,43 +0,0 @@ -# --- !Ups - -CREATE TABLE testify_record - ( - case_number VARCHAR(255) NOT NULL DEFAULT '', - person_id int, - constraint pk_testify_record primary key (case_number, person_id), - constraint fk_testify_person foreign key (person_id) references person(person_id), - constraint fk_testify_case foreign key (case_number) references "case"(case_number) - ); - -ALTER TABLE charge ADD constraint fk_charge_case foreign key (case_Id) references "case"(case_number); - -CREATE TABLE meeting - ( - id serial, - "date" DATE, - constraint pk_meeting primary key (id) - ); - -CREATE TABLE person_at_meeting - ( - meeting_id int, - person_id int, - role int, - constraint pk_person_at_meeting primary key (meeting_id, person_id, role), - constraint fk_PAM_meeting foreign key (meeting_id) references meeting(id), - constraint fk_PAM_person foreign key (person_id) references person(person_id) - ); - -ALTER TABLE "case" ADD COLUMN meeting_id int; -ALTER TABLE "case" ADD constraint fk_case_meeting foreign key (meeting_id) references meeting(id); - -# --- !Downs - -DROP TABLE testify_record; -ALTER TABLE charge DROP constraint fk_charge_case; -DROP TABLE person_at_meeting; -DROP TABLE meeting; - -ALTER TABLE "case" DROP constraint fk_case_meeting; -ALTER TABLE "case" DROP COLUMN meeting_id; - diff --git a/conf/evolutions/default/18.sql b/conf/evolutions/default/18.sql deleted file mode 100644 index fd31ae46..00000000 --- a/conf/evolutions/default/18.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE "person" ADD COLUMN grade varchar(8) not null default ''; - -# --- !Downs - -ALTER TABLE "person" DROP COLUMN grade; - diff --git a/conf/evolutions/default/19.sql b/conf/evolutions/default/19.sql deleted file mode 100644 index 8ff7c690..00000000 --- a/conf/evolutions/default/19.sql +++ /dev/null @@ -1,29 +0,0 @@ -# --- !Ups - -ALTER TABLE person_at_meeting ADD COLUMN id serial; - -ALTER TABLE "case" ALTER meeting_id SET NOT NULL; -ALTER TABLE "case" ADD COLUMN location VARCHAR(255) NOT NULL DEFAULT ''; -ALTER TABLE "case" ADD COLUMN writer_id INTEGER; -ALTER TABLE "case" ADD constraint fk_case_writer foreign key (writer_id) references person(person_id); - -UPDATE "case" SET findings='' WHERE findings IS NULL; -ALTER TABLE "case" ALTER findings SET NOT NULL; - -ALTER TABLE "testify_record" ADD COLUMN id serial; - -UPDATE charge SET resolution_plan='' WHERE resolution_plan IS NULL; -ALTER TABLE charge ALTER resolution_plan SET NOT NULL; - -# --- !Downs - -ALTER TABLE person_at_meeting DROP COLUMN id; - -ALTER TABLE "case" ALTER meeting_id DROP NOT NULL; -ALTER TABLE "case" DROP COLUMN location; -ALTER TABLE "case" DROP COLUMN writer_id; -ALTER TABLE "case" ALTER findings DROP NOT NULL; - -ALTER TABLE "testify_record" DROP COLUMN id; - -ALTER TABLE charge ALTER resolution_plan DROP NOT NULL; diff --git a/conf/evolutions/default/2.sql b/conf/evolutions/default/2.sql deleted file mode 100644 index 194a57f1..00000000 --- a/conf/evolutions/default/2.sql +++ /dev/null @@ -1,42 +0,0 @@ -# --- !Ups - -create table linked_account ( - id bigint not null, - user_id bigint, - provider_user_id varchar(255), - provider_key varchar(255), - constraint pk_linked_account primary key (id)) -; - -create table users ( - id bigint not null, - email varchar(255), - name varchar(255), - active boolean, - email_validated boolean, - constraint pk_users primary key (id)) -; - -create sequence linked_account_seq; - -create sequence users_seq; - -alter table linked_account add constraint fk_linked_account_user_1 foreign key (user_id) references users (id) on delete restrict on update restrict; -create index ix_linked_account_user_1 on linked_account (user_id); - - - -# --- !Downs - -SET REFERENTIAL_INTEGRITY FALSE; - -drop table if exists linked_account; - -drop table if exists users; - -SET REFERENTIAL_INTEGRITY TRUE; - -drop sequence if exists linked_account_seq; - -drop sequence if exists users_seq; - diff --git a/conf/evolutions/default/20.sql b/conf/evolutions/default/20.sql deleted file mode 100644 index a0c2174d..00000000 --- a/conf/evolutions/default/20.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE person add column display_name varchar(255) not null default ''; - -# --- !Downs - -ALTER TABLE person drop column display_name; diff --git a/conf/evolutions/default/21.sql b/conf/evolutions/default/21.sql deleted file mode 100644 index 48a84af5..00000000 --- a/conf/evolutions/default/21.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -CREATE TABLE allowed_ips (ip VARCHAR(30) primary key); -INSERT INTO allowed_ips (ip) VALUES('127.0.0.1'); - -# --- !Downs - -DROP TABLE allowed_ips; diff --git a/conf/evolutions/default/22.sql b/conf/evolutions/default/22.sql deleted file mode 100644 index b4f5cd2f..00000000 --- a/conf/evolutions/default/22.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE charge ADD COLUMN referred_to_sm BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE charge ADD COLUMN sm_decision text; - -# --- !Downs - -ALTER TABLE charge DROP COLUMN referred_to_sm; -ALTER TABLE charge DROP COLUMN sm_decision; diff --git a/conf/evolutions/default/23.sql b/conf/evolutions/default/23.sql deleted file mode 100644 index 9655b45c..00000000 --- a/conf/evolutions/default/23.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE rule ADD COLUMN removed BOOLEAN NOT NULL DEFAULT FALSE; - -# --- !Downs - -ALTER TABLE rule DROP COLUMN removed; diff --git a/conf/evolutions/default/24.sql b/conf/evolutions/default/24.sql deleted file mode 100644 index ba16a24d..00000000 --- a/conf/evolutions/default/24.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE charge ADD COLUMN sm_decision_date date; - -# --- !Downs - -ALTER TABLE charge DROP COLUMN sm_decision_date; diff --git a/conf/evolutions/default/25.sql b/conf/evolutions/default/25.sql deleted file mode 100644 index df6a0b51..00000000 --- a/conf/evolutions/default/25.sql +++ /dev/null @@ -1,14 +0,0 @@ -# --- !Ups - -CREATE TABLE email - ( - id serial, - message TEXT, - sent boolean not null, - deleted boolean not null, - constraint pk_email primary key (id) - ); - -# --- !Downs - -DROP TABLE email; diff --git a/conf/evolutions/default/26.sql b/conf/evolutions/default/26.sql deleted file mode 100644 index e27121c0..00000000 --- a/conf/evolutions/default/26.sql +++ /dev/null @@ -1,35 +0,0 @@ -# --- !Ups - -CREATE TABLE chapter - ( - id serial, - num integer not null, - title varchar(255) not null, - constraint pk_chapter primary key (id) - ); - -CREATE TABLE section - ( - id serial, - num integer not null, - title varchar(255) not null, - chapter_id integer not null, - constraint pk_section primary key (id), - constraint fk_section_chapter foreign key(chapter_id) references chapter(id) on delete restrict on update restrict - ); - -CREATE TABLE entry - ( - id serial, - num integer not null, - title varchar(255) not null, - section_id integer not null, - content text not null, - constraint pk_entry primary key (id), - constraint fk_entry_section foreign key(section_id) references section(id) on delete restrict on update restrict - ); -# --- !Downs - -drop table entry; -drop table section; -drop table chapter; diff --git a/conf/evolutions/default/27.sql b/conf/evolutions/default/27.sql deleted file mode 100644 index 7e14d4e9..00000000 --- a/conf/evolutions/default/27.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -alter table section alter num type varchar(8); -alter table entry alter num type varchar(8); - -# --- !Downs - -alter table section alter num type int; -alter table entry alter num type int; diff --git a/conf/evolutions/default/28.sql b/conf/evolutions/default/28.sql deleted file mode 100644 index 7df247d7..00000000 --- a/conf/evolutions/default/28.sql +++ /dev/null @@ -1,11 +0,0 @@ -# --- !Ups - -alter table chapter add column deleted boolean not null default false; -alter table section add column deleted boolean not null default false; -alter table entry add column deleted boolean not null default false; - -# --- !Downs - -alter table chapter drop column deleted; -alter table section drop column deleted; -alter table entry drop column deleted; diff --git a/conf/evolutions/default/29.sql b/conf/evolutions/default/29.sql deleted file mode 100644 index 264dbe95..00000000 --- a/conf/evolutions/default/29.sql +++ /dev/null @@ -1,22 +0,0 @@ -# --- !Ups - -alter table charge drop CONSTRAINT fk_charge_rule; -delete from charge; -alter table charge add CONSTRAINT fk_charge_entry foreign key(rule_id) references entry (id) on update restrict on delete restrict; - -drop table rule; - -# --- !Downs - -CREATE TABLE rule -( - id serial NOT NULL, - title character varying(255) NOT NULL DEFAULT ''::character varying, - removed boolean NOT NULL DEFAULT false, - CONSTRAINT pk_rule PRIMARY KEY (id) -); - -alter table charge drop CONSTRAINT fk_charge_entry; -alter table charge add CONSTRAINT fk_charge_rule FOREIGN KEY (rule_id) - REFERENCES rule (id) MATCH SIMPLE - ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/conf/evolutions/default/3.sql b/conf/evolutions/default/3.sql deleted file mode 100644 index a0dfc1f1..00000000 --- a/conf/evolutions/default/3.sql +++ /dev/null @@ -1,21 +0,0 @@ -# --- !Ups - -create table phone_numbers ( - id bigint not null, - person_id integer not null, - comment varchar(255), - number varchar(255), - constraint pk_phone_numbers primary key (id)) -; - -create sequence phone_numbers_seq; - -alter table phone_numbers add constraint fk_phone_numbers_person_1 foreign key (person_id) references person (person_id) on delete restrict on update restrict; -create index ix_phone_numbers_1 on phone_numbers (person_id); - - -# --- !Downs - -drop table if exists phone_numbers; -drop sequence if exists phone_numbers_seq; - diff --git a/conf/evolutions/default/30.sql b/conf/evolutions/default/30.sql deleted file mode 100644 index 2be054d7..00000000 --- a/conf/evolutions/default/30.sql +++ /dev/null @@ -1,38 +0,0 @@ -# --- !Ups - -CREATE TABLE manual_change -( - id serial, - - chapter_id INTEGER, - section_id INTEGER, - entry_id INTEGER, - - was_deleted BOOLEAN NOT NULL, - was_created BOOLEAN NOT NULL, - - old_title VARCHAR(255), - new_title VARCHAR(255), - old_content text, - new_content text, - old_num VARCHAR(8), - new_num VARCHAR(8), - - date_entered timestamp without time zone NOT NULL, - - CONSTRAINT pk_manual_change PRIMARY KEY(id), - CONSTRAINT fk_change_chapter FOREIGN KEY (chapter_id) - REFERENCES chapter (id) MATCH SIMPLE - ON UPDATE RESTRICT ON DELETE RESTRICT, - CONSTRAINT fk_change_section FOREIGN KEY (section_id) - REFERENCES section (id) MATCH SIMPLE - ON UPDATE RESTRICT ON DELETE RESTRICT, - CONSTRAINT fk_change_entry FOREIGN KEY (entry_id) - REFERENCES entry (id) MATCH SIMPLE - ON UPDATE RESTRICT ON DELETE RESTRICT - ); - - -# --- !Downs - -DROP TABLE manual_change; diff --git a/conf/evolutions/default/31.sql b/conf/evolutions/default/31.sql deleted file mode 100644 index e84a85f8..00000000 --- a/conf/evolutions/default/31.sql +++ /dev/null @@ -1,65 +0,0 @@ -# --- !Ups - -CREATE TABLE organization -( - id serial, - name VARCHAR(255), - constraint pk_organization PRIMARY KEY (id) - ); - -INSERT INTO organization (id, name) VALUES (1, 'Three Rivers Village School'); - -CREATE TABLE organization_hosts -( - host text, - organization_id INTEGER NOT NULL, - constraint pk_organization_hosts PRIMARY KEY(host), - constraint fk_organization_hosts_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict - ); - -ALTER TABLE allowed_ips ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE allowed_ips ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE allowed_ips ADD constraint fk_allowed_ips_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -ALTER TABLE chapter ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE chapter ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE chapter ADD constraint fk_chapter_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -ALTER TABLE email ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE email ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE email ADD constraint fk_email_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -ALTER TABLE meeting ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE meeting ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE meeting ADD constraint fk_meeting_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -ALTER TABLE person ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE person ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE person ADD constraint fk_person_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -ALTER TABLE tag ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE tag ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE tag ADD constraint fk_tag_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -ALTER TABLE task_list ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE task_list ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE task_list ADD constraint fk_task_list_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -ALTER TABLE users ADD COLUMN organization_id INTEGER NOT NULL DEFAULT 1; -ALTER TABLE users ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE users ADD constraint fk_users_organization foreign key(organization_id) references organization (id) on update restrict on delete restrict; - -# --- !Downs - -ALTER TABLE allowed_ips DROP COLUMN organization_id; -ALTER TABLE chapter DROP COLUMN organization_id; -ALTER TABLE email DROP COLUMN organization_id; -ALTER TABLE meeting DROP COLUMN organization_id; -ALTER TABLE person DROP COLUMN organization_id; -ALTER TABLE tag DROP COLUMN organization_id; -ALTER TABLE task_list DROP COLUMN organization_id; -ALTER TABLE users DROP COLUMN organization_id; - -DROP TABLE organization_hosts; -DROP TABLE organization; - diff --git a/conf/evolutions/default/32.sql b/conf/evolutions/default/32.sql deleted file mode 100644 index 88ffcf24..00000000 --- a/conf/evolutions/default/32.sql +++ /dev/null @@ -1,11 +0,0 @@ -# --- !Ups - -ALTER TABLE tag DROP constraint unique_title; -ALTER TABLE tag ADD CONSTRAINT unique_title_org UNIQUE (title, organization_id); - -# --- !Downs - -ALTER TABLE tag remove constraint unique_title_org; -ALTER TABLE tag ADD CONSTRAINT unique_title UNIQUE (title); - - diff --git a/conf/evolutions/default/33.sql b/conf/evolutions/default/33.sql deleted file mode 100644 index 7f345514..00000000 --- a/conf/evolutions/default/33.sql +++ /dev/null @@ -1,77 +0,0 @@ - first_name character varying(255), - last_name character varying(255), - notes text, - address character varying(255), - city character varying(255), - state character varying(255), - zip character varying(255), - neighborhood character varying(255), - email character varying(255), - -# --- !Ups - -UPDATE person SET last_name='' WHERE last_name IS NULL; -ALTER TABLE person ALTER COLUMN last_name SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN last_name SET NOT NULL; - -UPDATE person SET first_name='' WHERE first_name IS NULL; -ALTER TABLE person ALTER COLUMN first_name SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN first_name SET NOT NULL; - -UPDATE person SET notes='' WHERE notes IS NULL; -ALTER TABLE person ALTER COLUMN notes SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN notes SET NOT NULL; - -UPDATE person SET address='' WHERE address IS NULL; -ALTER TABLE person ALTER COLUMN address SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN address SET NOT NULL; - -UPDATE person SET city='' WHERE city IS NULL; -ALTER TABLE person ALTER COLUMN city SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN city SET NOT NULL; - -UPDATE person SET state='' WHERE state IS NULL; -ALTER TABLE person ALTER COLUMN state SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN state SET NOT NULL; - -UPDATE person SET zip='' WHERE zip IS NULL; -ALTER TABLE person ALTER COLUMN zip SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN zip SET NOT NULL; - -UPDATE person SET neighborhood='' WHERE neighborhood IS NULL; -ALTER TABLE person ALTER COLUMN neighborhood SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN neighborhood SET NOT NULL; - -UPDATE person SET email='' WHERE email IS NULL; -ALTER TABLE person ALTER COLUMN email SET DEFAULT ''; -ALTER TABLE person ALTER COLUMN email SET NOT NULL; - -# --- !Downs - -ALTER TABLE person ALTER COLUMN last_name DROP DEFAULT; -ALTER TABLE person ALTER COLUMN last_name DROP NOT NULL; - -ALTER TABLE person ALTER COLUMN first_name drop DEFAULT; -ALTER TABLE person ALTER COLUMN first_name drop NOT NULL; - -ALTER TABLE person ALTER COLUMN notes drop DEFAULT; -ALTER TABLE person ALTER COLUMN notes drop NOT NULL; - -ALTER TABLE person ALTER COLUMN address drop DEFAULT; -ALTER TABLE person ALTER COLUMN address drop NOT NULL; - -ALTER TABLE person ALTER COLUMN city drop DEFAULT; -ALTER TABLE person ALTER COLUMN city drop NOT NULL; - -ALTER TABLE person ALTER COLUMN state drop DEFAULT; -ALTER TABLE person ALTER COLUMN state drop NOT NULL; - -ALTER TABLE person ALTER COLUMN zip drop DEFAULT; -ALTER TABLE person ALTER COLUMN zip drop NOT NULL; - -ALTER TABLE person ALTER COLUMN neighborhood drop DEFAULT; -ALTER TABLE person ALTER COLUMN neighborhood drop NOT NULL; - -ALTER TABLE person ALTER COLUMN email drop DEFAULT; -ALTER TABLE person ALTER COLUMN email drop NOT NULL; - diff --git a/conf/evolutions/default/34.sql b/conf/evolutions/default/34.sql deleted file mode 100644 index 895a3654..00000000 --- a/conf/evolutions/default/34.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE chapter ALTER COLUMN num TYPE VARCHAR(8); - -# --- !Downs - -ALTER TABLE chapter ALTER COLUMN num TYPE int; diff --git a/conf/evolutions/default/35.sql b/conf/evolutions/default/35.sql deleted file mode 100644 index 6aac5d68..00000000 --- a/conf/evolutions/default/35.sql +++ /dev/null @@ -1,28 +0,0 @@ -# --- !Ups - -ALTER TABLE "case" ADD COLUMN id serial; - -ALTER TABLE charge RENAME case_id TO case_number; - -ALTER TABLE testify_record ADD COLUMN case_id INTEGER; -ALTER TABLE charge ADD COLUMN case_id INTEGER; - -UPDATE testify_record tr SET case_id=(SELECT id FROM "case" c WHERE tr.case_number = c.case_number); -UPDATE charge cg SET case_id=(SELECT id FROM "case" c WHERE cg.case_number = c.case_number); - -ALTER TABLE testify_record DROP constraint fk_testify_case; -ALTER TABLE testify_record DROP COLUMN case_number; -ALTER TABLE charge DROP constraint fk_charge_case; -ALTER TABLE charge DROP COLUMN case_number; - -ALTER TABLE "case" DROP constraint pk_case; -ALTER TABLE "case" ADD constraint pk_case_2 primary key (id); -ALTER TABLE "case" ADD constraint u_case_number_meeting UNIQUE (case_number, meeting_id); - -ALTER TABLE testify_record ADD CONSTRAINT fk_testify_case FOREIGN KEY (case_id) REFERENCES "case" (id); -ALTER TABLE charge ADD CONSTRAINT fk_charge_case FOREIGN KEY (case_id) REFERENCES "case" (id); - -# --- !Downs - --- ! There is no down from here. Sorry. You're on your own. - diff --git a/conf/evolutions/default/36.sql b/conf/evolutions/default/36.sql deleted file mode 100644 index 2c8e312d..00000000 --- a/conf/evolutions/default/36.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE "case" ADD COLUMN time VARCHAR(255) NOT NULL DEFAULT ''; - -# --- !Downs - -ALTER TABLE "case" DROP COLUMN time; - diff --git a/conf/evolutions/default/37.sql b/conf/evolutions/default/37.sql deleted file mode 100644 index 748b3f78..00000000 --- a/conf/evolutions/default/37.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE "case" ADD COLUMN severity VARCHAR(255) NOT NULL DEFAULT ''; - -# --- !Downs - -ALTER TABLE "case" DROP COLUMN severity; - diff --git a/conf/evolutions/default/38.sql b/conf/evolutions/default/38.sql deleted file mode 100644 index de9ec44d..00000000 --- a/conf/evolutions/default/38.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE "charge" ADD COLUMN minor_referral_destination VARCHAR(255) NOT NULL DEFAULT ''; - -# --- !Downs - -ALTER TABLE "charge" DROP COLUMN minor_referral_destination; - diff --git a/conf/evolutions/default/39.sql b/conf/evolutions/default/39.sql deleted file mode 100644 index 82ffa5f2..00000000 --- a/conf/evolutions/default/39.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE "charge" ADD COLUMN severity VARCHAR(255) NOT NULL DEFAULT ''; -alter table "case" drop column severity; - -# --- !Downs - -ALTER TABLE "charge" DROP COLUMN severity; -ALTER TABLE "case" ADD COLUMN severity VARCHAR(255) NOT NULL DEFAULT ''; diff --git a/conf/evolutions/default/4.sql b/conf/evolutions/default/4.sql deleted file mode 100644 index 6e73b2f0..00000000 --- a/conf/evolutions/default/4.sql +++ /dev/null @@ -1,43 +0,0 @@ -# --- !Ups - -CREATE TABLE person_tag ( - tag_id bigint NOT NULL, - person_id INTEGER NOT NULL, - creator_id bigint NOT NULL, - created timestamp DEFAULT NOW(), - constraint pk_person_tag primary key(tag_id, person_id) -); - - -CREATE TABLE tag ( - id bigint NOT NULL, - title VARCHAR(255) NOT NULL, - constraint pk_tag primary key(id), - constraint unique_title UNIQUE(title) -); - -create sequence tag_seq; - - - -alter table person_tag add constraint fk_person_tag_person_1 foreign key (person_id) references person (person_id) on delete restrict on update restrict; -create index ix_person_tag_1 on person_tag (person_id); - -alter table person_tag add constraint fk_person_tag_tag_1 foreign key (tag_id) references tag (id) on delete restrict on update restrict; -create index ix_person_tag_2 on person_tag (tag_id); - -alter table person_tag add constraint fk_person_tag_creator_1 foreign key (creator_id) references users (id) on delete restrict on update restrict; - - -ALTER TABLE person ALTER COLUMN dob TYPE DATE; -ALTER TABLE person ALTER COLUMN approximate_dob TYPE DATE; - - -# --- !Downs - -DROP TABLE IF EXISTS person_tag; -DROP TABLE IF EXISTS tag; -DROP sequence IF EXISTS tag_seq; - -ALTER TABLE person ALTER COLUMN dob TYPE timestamp; -ALTER TABLE person ALTER COLUMN approximate_dob TYPE timestamp; diff --git a/conf/evolutions/default/40.sql b/conf/evolutions/default/40.sql deleted file mode 100644 index 406b943a..00000000 --- a/conf/evolutions/default/40.sql +++ /dev/null @@ -1,26 +0,0 @@ -# --- !Ups - -CREATE TABLE person_tag_change -( - id serial NOT NULL, - person_id INTEGER NOT NULL, - tag_id INTEGER NOT NULL, - creator_id INTEGER NOT NULL, - time timestamp without time zone DEFAULT now(), - was_add BOOLEAN NOT NULL, - constraint pk_ptc primary key(id), - constraint fk_ptc_person foreign key(person_id) references person(person_id), - constraint fk_ptc_tag foreign key(tag_id) references tag(id), - constraint fk_ptc_creator foreign key(creator_id) references users(id) -); - -INSERT INTO person_tag_change (person_id, tag_id, creator_id, time, was_add) - (SELECT person_id, tag_id, creator_id, created, true FROM person_tag); - -ALTER TABLE person_tag DROP constraint fk_person_tag_creator_1; -ALTER TABLE person_tag DROP creator_id; -ALTER TABLE person_tag DROP created; - -# --- !Downs - - diff --git a/conf/evolutions/default/41.sql b/conf/evolutions/default/41.sql deleted file mode 100644 index 5bb27982..00000000 --- a/conf/evolutions/default/41.sql +++ /dev/null @@ -1,22 +0,0 @@ -# --- !Ups - -CREATE TABLE mailchimp_sync -( - id serial NOT NULL, - tag_id INTEGER NOT NULL, - mailchimp_list_id varchar(255) NOT NULL, - sync_local_adds BOOLEAN NOT NULL, - sync_local_removes BOOLEAN NOT NULL, - last_sync timestamp without time zone, - - constraint pk_mailchimp_sync primary key(id), - constraint fk_mailchimp_sync_tag foreign key(tag_id) references tag(id) -); - -ALTER TABLE organization ADD COLUMN mailchimp_api_key VARCHAR(255); - -# --- !Downs - -DROP TABLE mailchimp_sync; - -ALTER TABLE organization DROP mailchimp_api_key; diff --git a/conf/evolutions/default/42.sql b/conf/evolutions/default/42.sql deleted file mode 100644 index 3d0aacc5..00000000 --- a/conf/evolutions/default/42.sql +++ /dev/null @@ -1,23 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN mailchimp_last_sync_person_changes timestamp without time zone; -ALTER TABLE organization ALTER COLUMN mailchimp_api_key SET DEFAULT ''; -update organization set mailchimp_api_key='' where mailchimp_api_key is null; -ALTER TABLE organization ALTER COLUMN mailchimp_api_key SET NOT NULL; - -CREATE TABLE person_change -( - person_id INTEGER NOT NULL, - old_email VARCHAR(255) NOT NULL, - new_email VARCHAR(255) NOT NULL, - "time" timestamp without time zone DEFAULT now(), - - constraint fk_person_change_person foreign key(person_id) references person(person_id) -); - - -# --- !Downs - -DROP TABLE person_change; - -ALTER TABLE organization DROP mailchimp_last_sync_person_changes; \ No newline at end of file diff --git a/conf/evolutions/default/43.sql b/conf/evolutions/default/43.sql deleted file mode 100644 index 7214c453..00000000 --- a/conf/evolutions/default/43.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN mailchimp_updates_email varchar(255) DEFAULT '' NOT NULL; - - -# --- !Downs - -ALTER TABLE organization DROP mailchimp_updates_email; \ No newline at end of file diff --git a/conf/evolutions/default/44.sql b/conf/evolutions/default/44.sql deleted file mode 100644 index 86c50c4e..00000000 --- a/conf/evolutions/default/44.sql +++ /dev/null @@ -1,27 +0,0 @@ -# --- !Ups - -ALTER TABLE testify_record ADD COLUMN role INTEGER DEFAULT 0 NOT NULL; -ALTER TABLE testify_record RENAME TO person_at_case; - -INSERT INTO person_at_case (person_id, case_id, role) - (SELECT writer_id, id, 1 FROM "case" WHERE writer_id IS NOT NULL); - -ALTER TABLE "case" DROP constraint fk_case_writer; -ALTER TABLE "case" DROP writer_id; - -# --- !Downs - -ALTER TABLE "case" ADD COLUMN writer_id INTEGER; -ALTER TABLE "case" ADD constraint fk_case_writer FOREIGN KEY (writer_id) REFERENCES person (person_id); - ---- We could throw away some data here if there was more than ---- one writer. In the old world we can only record one. -UPDATE "case" c - SET writer_id = pac.person_id - FROM person_at_case pac - WHERE c.id=pac.case_id AND pac.role=1; - -ALTER TABLE person_at_case RENAME TO testify_record; - -DELETE FROM testify_record WHERE role != 0; -ALTER TABLE testify_record DROP COLUMN role; \ No newline at end of file diff --git a/conf/evolutions/default/45.sql b/conf/evolutions/default/45.sql deleted file mode 100644 index cca96ce8..00000000 --- a/conf/evolutions/default/45.sql +++ /dev/null @@ -1,22 +0,0 @@ -# --- !Ups - -ALTER TABLE ENTRY ALTER num TYPE text; -ALTER TABLE section ALTER num TYPE text; -ALTER TABLE chapter ALTER num TYPE text; - -ALTER TABLE manual_change ALTER old_num TYPE text; -ALTER TABLE manual_change ALTER new_num TYPE text; - -ALTER TABLE person ALTER gender TYPE text; -ALTER TABLE person ALTER grade TYPE text; - -# --- !Downs - -ALTER TABLE ENTRY ALTER num TYPE VARCHAR(8); -ALTER TABLE section ALTER num TYPE VARCHAR(8); -ALTER TABLE chapter ALTER num TYPE VARCHAR(8); -ALTER TABLE manual_change ALTER old_num TYPE VARCHAR(8); -ALTER TABLE manual_change ALTER new_num TYPE VARCHAR(8); - -ALTER TABLE person ALTER gender TYPE VARCHAR(10); -ALTER TABLE person ALTER grade TYPE VARCHAR(8); \ No newline at end of file diff --git a/conf/evolutions/default/46.sql b/conf/evolutions/default/46.sql deleted file mode 100644 index 2be7c50c..00000000 --- a/conf/evolutions/default/46.sql +++ /dev/null @@ -1,13 +0,0 @@ -# --- !Ups - -ALTER TABLE charge ADD COLUMN rp_complete BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE charge ADD COLUMN rp_complete_date timestamp; - -UPDATE charge SET rp_complete = TRUE; -UPDATE charge SET rp_complete_date = meeting.DATE FROM "case", meeting - WHERE charge.case_id="case".id AND "case".meeting_id=meeting.id; - -# --- !Downs - -ALTER TABLE charge DROP COLUMN rp_complete; -ALTER TABLE charge DROP COLUMN rp_complete_date; diff --git a/conf/evolutions/default/47.sql b/conf/evolutions/default/47.sql deleted file mode 100644 index 81de7df0..00000000 --- a/conf/evolutions/default/47.sql +++ /dev/null @@ -1,25 +0,0 @@ -# --- !Ups - -CREATE TABLE case_meeting -( - case_id INTEGER NOT NULL, - meeting_id integer NOT NULL, - CONSTRAINT pk_case_meeting PRIMARY KEY (case_id, meeting_id), - - CONSTRAINT fk_case_meeting_case FOREIGN KEY (case_id) - REFERENCES "case" (id) MATCH SIMPLE - ON UPDATE RESTRICT ON DELETE CASCADE, - - CONSTRAINT fk_case_meeting_meeting FOREIGN KEY (meeting_id) - REFERENCES meeting (id) MATCH SIMPLE - ON UPDATE RESTRICT ON DELETE CASCADE -); - -ALTER TABLE "case" ADD COLUMN date_closed DATE; - -UPDATE "case" SET date_closed=m.DATE FROM meeting m WHERE "case".meeting_id=m.id; - -# --- !Downs - -DROP TABLE case_meeting; -ALTER TABLE "case" DROP COLUMN date_closed; diff --git a/conf/evolutions/default/48.sql b/conf/evolutions/default/48.sql deleted file mode 100644 index fdc0cbea..00000000 --- a/conf/evolutions/default/48.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -alter table phone_numbers alter column id set default nextval('phone_numbers_seq'::regclass); - -# --- !Downs - -alter table phone_numbers alter column id DROP DEFAULT; diff --git a/conf/evolutions/default/49.sql b/conf/evolutions/default/49.sql deleted file mode 100644 index aef7e8e0..00000000 --- a/conf/evolutions/default/49.sql +++ /dev/null @@ -1,41 +0,0 @@ -# --- !Ups - -CREATE TABLE attendance_code -( - id serial NOT NULL, - organization_id integer NOT NULL, - code VARCHAR(8) NOT NULL, - description text NOT NULL, - color VARCHAR(16) NOT NULL, - CONSTRAINT pk_attendance_code PRIMARY KEY(id), - CONSTRAINT fk_attendance_code_organization FOREIGN KEY (organization_id) references organization(id) -); - -CREATE TABLE attendance_day -( - id serial NOT NULL, - day DATE NOT NULL, - person_id INTEGER NOT NULL, - code VARCHAR(8), - start_time time, - end_time time, - CONSTRAINT pk_attendance_day PRIMARY KEY(id), - CONSTRAINT fk_attendance_day_person FOREIGN KEY (person_id) references person(person_id) -); - -CREATE TABLE attendance_week -( - id serial NOT NULL, - person_id INTEGER NOT NULL, - monday DATE NOT NULL, - extra_hours INTEGER NOT NULL, - CONSTRAINT pk_attendance_week PRIMARY KEY(id), - CONSTRAINT fk_attendance_week_person FOREIGN KEY (person_id) references person(person_id) -); - -# --- !Downs - -DROP TABLE attendance_week; -DROP TABLE attendance_day; -DROP TABLE attendance_code; - diff --git a/conf/evolutions/default/5.sql b/conf/evolutions/default/5.sql deleted file mode 100644 index bc1f94d5..00000000 --- a/conf/evolutions/default/5.sql +++ /dev/null @@ -1,21 +0,0 @@ -# --- !Ups - -CREATE TABLE comments ( - id INTEGER NOT NULL, - person_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - message TEXT, - created timestamp DEFAULT NOW(), - constraint pk_comments primary key(id), - constraint fk_comments_person foreign key (person_id) references person (person_id) on delete restrict on update restrict, - constraint fk_comments_user foreign key (user_id) references users (id) on delete restrict on update restrict -); - -create sequence comments_seq; - - -# --- !Downs - -DROP TABLE IF EXISTS comments; -DROP sequence IF EXISTS comments_seq; - diff --git a/conf/evolutions/default/50.sql b/conf/evolutions/default/50.sql deleted file mode 100644 index 45ea66c9..00000000 --- a/conf/evolutions/default/50.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE attendance_week ALTER COLUMN extra_hours TYPE REAL; - -# --- !Downs - -ALTER TABLE attendance_week ALTER COLUMN extra_hours TYPE INTEGER; - diff --git a/conf/evolutions/default/51.sql b/conf/evolutions/default/51.sql deleted file mode 100644 index 26a87fa5..00000000 --- a/conf/evolutions/default/51.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -alter table linked_account alter column id set default nextval('linked_account_seq'::regclass); -alter table users alter column id set default nextval('users_seq'::regclass); - -# --- !Downs - -alter table linked_account alter column id DROP DEFAULT; -alter table users alter column id drop default; diff --git a/conf/evolutions/default/52.sql b/conf/evolutions/default/52.sql deleted file mode 100644 index 7adf419e..00000000 --- a/conf/evolutions/default/52.sql +++ /dev/null @@ -1,16 +0,0 @@ -# --- !Ups - -CREATE TABLE notification_rule ( - id serial, - tag_id INTEGER, - the_type INTEGER NOT NULL, - email text NOT NULL, - organization_id INTEGER NOT NULL, - CONSTRAINT pk_notification_rule PRIMARY KEY(id), - CONSTRAINT fk_notifiaction_rule_tag FOREIGN KEY(tag_id) references tag(id), - CONSTRAINT fk_notifiaction_rule_organization FOREIGN KEY(organization_id) references organization(id) -); - -# --- !Downs - -DROP TABLE notification_rule; diff --git a/conf/evolutions/default/53.sql b/conf/evolutions/default/53.sql deleted file mode 100644 index 3eb0894e..00000000 --- a/conf/evolutions/default/53.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE TASK ALTER enabled DROP DEFAULT; - -# --- !Downs - -ALTER TABLE TASK ALTER enabled SET DEFAULT TRUE; - diff --git a/conf/evolutions/default/54.sql b/conf/evolutions/default/54.sql deleted file mode 100644 index 7f943876..00000000 --- a/conf/evolutions/default/54.sql +++ /dev/null @@ -1,21 +0,0 @@ -# --- !Ups - -CREATE TABLE user_role ( - id serial, - user_id INTEGER NOT NULL, - role text NOT NULL, - CONSTRAINT pk_user_role primary key(id), - CONSTRAINT fk_user_role_users foreign key(user_id) references users(id) -); - -INSERT INTO user_role(user_id, role) (SELECT id, 'all-access' FROM users); - -ALTER table users ALTER COLUMN id TYPE INTEGER; - -ALTER TABLE users ALTER COLUMN organization_id DROP NOT NULL; - -# --- !Downs - -DROP TABLE user_role; -ALTER TABLE users ALTER COLUMN id TYPE bigint; -ALTER TABLE users ALTER COLUMN organization_id SET NOT NULL; diff --git a/conf/evolutions/default/55.sql b/conf/evolutions/default/55.sql deleted file mode 100644 index ef062205..00000000 --- a/conf/evolutions/default/55.sql +++ /dev/null @@ -1,10 +0,0 @@ -# --- !Ups - -ALTER TABLE attendance_code ALTER COLUMN code TYPE VARCHAR(64); -ALTER TABLE attendance_day ALTER COLUMN code TYPE VARCHAR(64); - -# --- !Downs - -ALTER TABLE attendance_code ALTER COLUMN code TYPE VARCHAR(8); -ALTER TABLE attendance_day ALTER COLUMN code TYPE VARCHAR(8); - diff --git a/conf/evolutions/default/56.sql b/conf/evolutions/default/56.sql deleted file mode 100644 index 9e4091d3..00000000 --- a/conf/evolutions/default/56.sql +++ /dev/null @@ -1,16 +0,0 @@ -# --- !Ups - -ALTER TABLE donation ALTER COLUMN DATE SET DEFAULT (now() at time zone 'utc'); -ALTER TABLE person_tag_change ALTER COLUMN time SET DEFAULT (now() at time zone 'utc'); -ALTER TABLE person_change ALTER COLUMN "time" SET DEFAULT (now() at time zone 'utc'); -ALTER TABLE comments ALTER COLUMN created SET DEFAULT (now() at time zone 'utc'); -ALTER TABLE person ALTER COLUMN created SET DEFAULT (now() at time zone 'utc'); - -# --- !Downs - -ALTER TABLE donation ALTER COLUMN DATE SET DEFAULT now(); -ALTER TABLE person_tag_change ALTER COLUMN time SET DEFAULT now(); -ALTER TABLE person_change ALTER COLUMN "time" SET DEFAULT now(); -ALTER TABLE comments ALTER COLUMN created SET DEFAULT now(); -ALTER TABLE person ALTER COLUMN created SET DEFAULT now(); - diff --git a/conf/evolutions/default/57.sql b/conf/evolutions/default/57.sql deleted file mode 100644 index f7b98073..00000000 --- a/conf/evolutions/default/57.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE attendance_week add constraint u_attendance_week unique(person_id, monday); -ALTER TABLE attendance_day add constraint u_attendance_day unique(person_id, day); - -# --- !Downs - -alter table attendance_week drop constraint u_attendance_week; -alter table attendance_day drop constraint u_attendance_day; diff --git a/conf/evolutions/default/58.sql b/conf/evolutions/default/58.sql deleted file mode 100644 index 357c153d..00000000 --- a/conf/evolutions/default/58.sql +++ /dev/null @@ -1,17 +0,0 @@ -# --- !Ups - -CREATE MATERIALIZED VIEW entry_index AS -SELECT entry.id, - chapter.organization_id, - (to_tsvector(entry.content) || to_tsvector(entry.title)) as document -FROM entry -JOIN section ON entry.section_id = section.id -JOIN chapter ON section.chapter_id = chapter.id -WHERE entry.deleted=false AND section.deleted=false AND chapter.deleted=false; - -CREATE INDEX idx_entry_index ON entry_index USING gin(document); - -# --- !Downs - -DROP INDEX idx_entry_index; -DROP MATERIALIZED VIEW entry_index; diff --git a/conf/evolutions/default/59.sql b/conf/evolutions/default/59.sql deleted file mode 100644 index 38fdb015..00000000 --- a/conf/evolutions/default/59.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -alter table linked_account add constraint u_linked_account UNIQUE(provider_key, provider_user_id); - -# --- !Downs - -alter table linked_account drop constraint u_linked_account; diff --git a/conf/evolutions/default/6.sql b/conf/evolutions/default/6.sql deleted file mode 100644 index 5ea5529d..00000000 --- a/conf/evolutions/default/6.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE users ADD constraint users_unique_email_1 UNIQUE(email); - -# --- !Downs - -ALTER TABLE users DROP constraint users_unique_email_1; diff --git a/conf/evolutions/default/60.sql b/conf/evolutions/default/60.sql deleted file mode 100644 index 15ac9804..00000000 --- a/conf/evolutions/default/60.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN printer_email varchar(255) DEFAULT '' NOT NULL; - - -# --- !Downs - -ALTER TABLE organization DROP printer_email; diff --git a/conf/evolutions/default/61.sql b/conf/evolutions/default/61.sql deleted file mode 100644 index 72bfde10..00000000 --- a/conf/evolutions/default/61.sql +++ /dev/null @@ -1,13 +0,0 @@ -# --- !Ups - -ALTER TABLE tag ADD COLUMN show_in_jc boolean DEFAULT false NOT NULL; - -UPDATE tag set show_in_jc=(title='Staff' or title='Current Student'); - -ALTER TABLE tag add column show_in_menu boolean default true not null; - - -# --- !Downs - -ALTER TABLE tag DROP show_in_menu; -ALTER TABLE tag DROP show_in_jc; diff --git a/conf/evolutions/default/62.sql b/conf/evolutions/default/62.sql deleted file mode 100644 index fb6f7966..00000000 --- a/conf/evolutions/default/62.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN jc_reset_day int DEFAULT 3 NOT NULL; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN jc_reset_day; diff --git a/conf/evolutions/default/63.sql b/conf/evolutions/default/63.sql deleted file mode 100644 index f6bf4bb8..00000000 --- a/conf/evolutions/default/63.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN show_history_in_print boolean DEFAULT true NOT NULL; -ALTER TABLE organization ADD COLUMN show_last_modified_in_print boolean DEFAULT true NOT NULL; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN show_history_in_print; -ALTER TABLE organization DROP COLUMN show_last_modified_in_print; diff --git a/conf/evolutions/default/64.sql b/conf/evolutions/default/64.sql deleted file mode 100644 index 9766f25d..00000000 --- a/conf/evolutions/default/64.sql +++ /dev/null @@ -1,49 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN show_custodia BOOLEAN default false not null; -ALTER TABLE organization ADD COLUMN show_attendance BOOLEAN default true not null; -ALTER TABLE organization ADD COLUMN short_name VARCHAR(255) default '' not null; -ALTER TABLE organization ADD COLUMN custodia_password VARCHAR(255) default '' not null; - -update organization set short_name='TRVS' where id=1; -update organization set short_name='PFS' where id=2; -update organization set short_name='Fairhaven' where id=3; -update organization set short_name='TCS' where id=4; -update organization set short_name='MLC' where id=5; -update organization set short_name='TOS' where id=6; -update organization set short_name='HSS' where id=7; -update organization set short_name='CSS' where id=8; -update organization set short_name='Sandbox' where id=9; - -create role custodia login password '123'; - -grant select on all tables in schema public to custodia; - -create schema if not exists overseer; -grant all on schema overseer to custodia; -grant all on all tables in schema overseer to custodia; -grant all on all sequences in schema overseer to custodia; - -create schema if not exists demo; -grant all on schema demo to custodia; -grant all on all sequences in schema demo to custodia; -grant all on all tables in schema demo to custodia; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN show_custodia; -ALTER TABLE organization DROP COLUMN show_attendance; -ALTER TABLE organization DROP COLUMN short_name; -ALTER TABLE organization DROP COLUMN custodia_password; - -revoke select on all tables in schema public from custodia; - -revoke all on schema overseer from custodia; -revoke all on all tables in schema overseer from custodia; -revoke all on all sequences in schema overseer from custodia; - -revoke all on schema demo from custodia; -revoke all on all sequences in schema demo from custodia; -revoke all on all tables in schema demo from custodia; - -drop role custodia; diff --git a/conf/evolutions/default/65.sql b/conf/evolutions/default/65.sql deleted file mode 100644 index 27fffe1c..00000000 --- a/conf/evolutions/default/65.sql +++ /dev/null @@ -1,10 +0,0 @@ -# --- !Ups - -update person set - first_name=TRIM(CONCAT(first_name, ' ', last_name)), - last_name='' - where last_name != '' and is_family=true; - - -# --- !Downs - diff --git a/conf/evolutions/default/66.sql b/conf/evolutions/default/66.sql deleted file mode 100644 index 26bf9743..00000000 --- a/conf/evolutions/default/66.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -alter table tag add column show_in_attendance boolean not null default false; -update tag set show_in_attendance=show_in_jc; - -# --- !Downs - -alter table tag drop column show_in_attendance; diff --git a/conf/evolutions/default/67.sql b/conf/evolutions/default/67.sql deleted file mode 100644 index 7cf0dbee..00000000 --- a/conf/evolutions/default/67.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -alter table organization add column show_accounting boolean not null default false; - -# --- !Downs - -alter table organization drop column show_accounting; diff --git a/conf/evolutions/default/68.sql b/conf/evolutions/default/68.sql deleted file mode 100644 index 226b5219..00000000 --- a/conf/evolutions/default/68.sql +++ /dev/null @@ -1,28 +0,0 @@ -# --- !Ups - -CREATE TABLE institution ( - id serial, - organization_id integer NOT NULL, - name text NOT NULL, - type integer NOT NULL, - CONSTRAINT pk_institution primary key(id), - CONSTRAINT fk_institution_organization FOREIGN KEY (organization_id) references organization(id) -); - -CREATE TABLE account ( - id serial, - organization_id integer NOT NULL, - person_id integer, - institution_id integer, - type integer NOT NULL, - initial_balance decimal NOT NULL, - CONSTRAINT pk_account primary key(id), - CONSTRAINT fk_account_organization FOREIGN KEY (organization_id) references organization(id), - CONSTRAINT fk_account_person FOREIGN KEY (person_id) references person(person_id), - CONSTRAINT fk_account_institution FOREIGN KEY (institution_id) references institution(id) -); - -# --- !Downs - -DROP TABLE account; -DROP TABLE institution; \ No newline at end of file diff --git a/conf/evolutions/default/69.sql b/conf/evolutions/default/69.sql deleted file mode 100644 index 249f96cc..00000000 --- a/conf/evolutions/default/69.sql +++ /dev/null @@ -1,22 +0,0 @@ -# --- !Ups - -CREATE TABLE transactions ( - id serial, - organization_id integer NOT NULL, - from_account_id integer, - to_account_id integer, - from_name text NOT NULL, - to_name text NOT NULL, - description text NOT NULL, - type integer NOT NULL, - amount decimal NOT NULL, - date_created timestamp NOT NULL, - CONSTRAINT pk_transaction primary key(id), - CONSTRAINT fk_transaction_organization FOREIGN KEY (organization_id) references organization(id), - CONSTRAINT fk_transaction_from_account FOREIGN KEY (from_account_id) references account(id), - CONSTRAINT fk_transaction_to_account FOREIGN KEY (to_account_id) references account(id) -); - -# --- !Downs - -DROP TABLE transaction; \ No newline at end of file diff --git a/conf/evolutions/default/7.sql b/conf/evolutions/default/7.sql deleted file mode 100644 index beb313d0..00000000 --- a/conf/evolutions/default/7.sql +++ /dev/null @@ -1,17 +0,0 @@ -# --- !Ups - -ALTER TABLE person ALTER person_id SET DEFAULT nextval('person_seq'); -ALTER TABLE person ALTER is_family SET DEFAULT FALSE; -UPDATE person SET is_family=FALSE WHERE is_family IS NULL; -ALTER TABLE person ALTER is_family SET NOT NULL; - -ALTER TABLE comments ALTER id SET DEFAULT nextval('comments_seq'); - -ALTER TABLE tag ALTER id SET DEFAULT nextval('tag_seq'); - -# --- !Downs - -ALTER TABLE person ALTER person_id DROP DEFAULT; -ALTER TABLE comments ALTER id DROP DEFAULT; -ALTER TABLE tag ALTER id DROP DEFAULT; - diff --git a/conf/evolutions/default/70.sql b/conf/evolutions/default/70.sql deleted file mode 100644 index 4b2c784e..00000000 --- a/conf/evolutions/default/70.sql +++ /dev/null @@ -1,24 +0,0 @@ -# --- !Ups - -ALTER TABLE account ADD COLUMN name text NOT NULL DEFAULT ''; - -ALTER TABLE account DROP CONSTRAINT fk_account_institution; -ALTER TABLE account DROP COLUMN institution_id; - -DROP TABLE institution; - -# --- !Downs - -CREATE TABLE institution ( - id serial, - organization_id integer NOT NULL, - name text NOT NULL, - type integer NOT NULL, - CONSTRAINT pk_institution primary key(id), - CONSTRAINT fk_institution_organization FOREIGN KEY (organization_id) REFERENCES organization(id) -); - -ALTER TABLE account ADD COLUMN institution_id integer; -ALTER TABLE account ADD CONSTRAINT fk_account_institution FOREIGN KEY (institution_id) REFERENCES institution(id) - -ALTER TABLE account DROP COLUMN name; \ No newline at end of file diff --git a/conf/evolutions/default/71.sql b/conf/evolutions/default/71.sql deleted file mode 100644 index 85fae0a7..00000000 --- a/conf/evolutions/default/71.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE transactions ADD COLUMN created_by_user_id integer; - -# --- !Downs - -ALTER TABLE transactions DROP COLUMN created_by_user_id; \ No newline at end of file diff --git a/conf/evolutions/default/72.sql b/conf/evolutions/default/72.sql deleted file mode 100644 index 6d87c3c1..00000000 --- a/conf/evolutions/default/72.sql +++ /dev/null @@ -1,8 +0,0 @@ -# --- !Ups - -ALTER TABLE tag ADD COLUMN show_in_account_balances boolean; -UPDATE tag SET show_in_account_balances = show_in_jc; - -# --- !Downs - -ALTER TABLE tag DROP COLUMN show_in_account_balances; \ No newline at end of file diff --git a/conf/evolutions/default/73.sql b/conf/evolutions/default/73.sql deleted file mode 100644 index abf8c35f..00000000 --- a/conf/evolutions/default/73.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE transactions ADD COLUMN archived boolean NOT NULL DEFAULT(false); - -# --- !Downs - -ALTER TABLE transactions DROP COLUMN archived; \ No newline at end of file diff --git a/conf/evolutions/default/74.sql b/conf/evolutions/default/74.sql deleted file mode 100644 index 2fc6a58b..00000000 --- a/conf/evolutions/default/74.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE account ADD COLUMN monthly_credit decimal NOT NULL DEFAULT(0); - -# --- !Downs - -ALTER TABLE account DROP COLUMN monthly_credit; \ No newline at end of file diff --git a/conf/evolutions/default/75.sql b/conf/evolutions/default/75.sql deleted file mode 100644 index 53eb56e4..00000000 --- a/conf/evolutions/default/75.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE account ADD COLUMN date_last_monthly_credit timestamp; - -# --- !Downs - -ALTER TABLE account DROP COLUMN date_last_monthly_credit; \ No newline at end of file diff --git a/conf/evolutions/default/76.sql b/conf/evolutions/default/76.sql deleted file mode 100644 index 938c72a7..00000000 --- a/conf/evolutions/default/76.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE meeting ADD CONSTRAINT unq_org_date UNIQUE (organization_id, date); - -# --- !Downs - -ALTER TABLE meeting DROP CONSTRAINT unq_org_date; diff --git a/conf/evolutions/default/77.sql b/conf/evolutions/default/77.sql deleted file mode 100644 index d10b79cd..00000000 --- a/conf/evolutions/default/77.sql +++ /dev/null @@ -1,19 +0,0 @@ -# --- !Ups - -ALTER TABLE attendance_code ADD COLUMN counts_toward_attendance boolean NOT NULL DEFAULT(false); - -ALTER TABLE organization ADD COLUMN attendance_show_percent boolean NOT NULL DEFAULT(false); -ALTER TABLE organization ADD COLUMN attendance_enable_partial_days boolean NOT NULL DEFAULT(false); -ALTER TABLE organization ADD COLUMN attendance_day_latest_start_time time; -ALTER TABLE organization ADD COLUMN attendance_day_min_hours integer; -ALTER TABLE organization ADD COLUMN attendance_partial_day_value decimal; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_partial_day_value; -ALTER TABLE organization DROP COLUMN attendance_day_min_hours; -ALTER TABLE organization DROP COLUMN attendance_day_latest_start_time; -ALTER TABLE organization DROP COLUMN attendance_enable_partial_days; -ALTER TABLE organization DROP COLUMN attendance_show_percent; - -ALTER TABLE attendance_code DROP COLUMN counts_toward_attendance; \ No newline at end of file diff --git a/conf/evolutions/default/78.sql b/conf/evolutions/default/78.sql deleted file mode 100644 index d06adb2f..00000000 --- a/conf/evolutions/default/78.sql +++ /dev/null @@ -1,34 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN enable_case_references boolean NOT NULL DEFAULT(false); - -ALTER TABLE entry ADD COLUMN is_breaking_res_plan boolean NOT NULL DEFAULT(false); - -ALTER TABLE charge ADD COLUMN referenced_charge_id integer; -ALTER TABLE charge ADD CONSTRAINT fk_charge_charge FOREIGN KEY (referenced_charge_id) REFERENCES charge(id); - -CREATE TABLE case_reference ( - referencing_case integer NOT NULL, - referenced_case integer NOT NULL, - CONSTRAINT fk_referencing_case FOREIGN KEY (referencing_case) REFERENCES "case"(id), - CONSTRAINT fk_referenced_case FOREIGN KEY (referenced_case) REFERENCES "case"(id) -); - -CREATE TABLE charge_reference ( - referencing_case integer NOT NULL, - referenced_charge integer NOT NULL, - CONSTRAINT fk_referencing_case FOREIGN KEY (referencing_case) REFERENCES "case"(id), - CONSTRAINT fk_referenced_charge FOREIGN KEY (referenced_charge) REFERENCES charge(id) -); - -# --- !Downs - -DROP TABLE charge_reference; -DROP TABLE case_reference; - -ALTER TABLE charge DROP CONSTRAINT fk_charge_charge; -ALTER TABLE charge DROP COLUMN referenced_charge_id; - -ALTER TABLE entry DROP COLUMN is_breaking_res_plan; - -ALTER TABLE organization DROP COLUMN enable_case_references; diff --git a/conf/evolutions/default/79.sql b/conf/evolutions/default/79.sql deleted file mode 100644 index bcc3dcfe..00000000 --- a/conf/evolutions/default/79.sql +++ /dev/null @@ -1,6 +0,0 @@ -# --- !Ups -ALTER TABLE users ADD COLUMN hashed_password TEXT NOT NULL DEFAULT(''); - -# --- !Downs - -ALTER TABLE users DROP COLUMN hashed_password; diff --git a/conf/evolutions/default/8.sql b/conf/evolutions/default/8.sql deleted file mode 100644 index f365146f..00000000 --- a/conf/evolutions/default/8.sql +++ /dev/null @@ -1,39 +0,0 @@ -# --- !Ups - - -CREATE TABLE task_list ( - id serial, - title VARCHAR(255), - tag_id INTEGER, - constraint pk_task_list primary key(id), - constraint fk_task_list_tag foreign key(tag_id) references tag(id) ON DELETE restrict ON UPDATE restrict -); - -CREATE TABLE TASK -( - id serial, - title VARCHAR(255), - task_list_id INTEGER, - sort_order INTEGER, - constraint pk_task primary key (id), - constraint fk_task_task_list foreign key(task_list_id) references task_list(id) ON DELETE restrict ON UPDATE restrict -); - -CREATE TABLE completed_task ( - id serial, - task_id INTEGER, - person_id INTEGER, - comment_id INTEGER, - constraint pk_completed_task primary key (id), - constraint fk_completed_task_task foreign key(task_id) references TASK (id) ON DELETE restrict ON UPDATE restrict, - constraint fk_completed_task_person foreign key(person_id) references person (person_id) ON DELETE restrict ON UPDATE restrict, - constraint fk_completed_task_comment foreign key(comment_id) references comments(id) ON DELETE restrict ON UPDATE restrict, - constraint unique_completed_task_1 UNIQUE(task_id, person_id) -); - -# --- !Downs - -DROP TABLE IF EXISTS completed_task; -DROP TABLE IF EXISTS task; -DROP TABLE IF EXISTS task_list; - diff --git a/conf/evolutions/default/80.sql b/conf/evolutions/default/80.sql deleted file mode 100644 index e6df460c..00000000 --- a/conf/evolutions/default/80.sql +++ /dev/null @@ -1,6 +0,0 @@ -# --- !Ups -ALTER TABLE person ADD COLUMN pin VARCHAR(10) NOT NULL DEFAULT(''); - -# --- !Downs - -ALTER TABLE person DROP COLUMN pin; diff --git a/conf/evolutions/default/81.sql b/conf/evolutions/default/81.sql deleted file mode 100644 index 8e30b6de..00000000 --- a/conf/evolutions/default/81.sql +++ /dev/null @@ -1,5 +0,0 @@ -# --- !Ups -ALTER TABLE organization ADD COLUMN show_electronic_signin boolean NOT NULL DEFAULT false; - -# --- !Downs -ALTER TABLE organization DROP COLUMN show_electronic_signin; diff --git a/conf/evolutions/default/82.sql b/conf/evolutions/default/82.sql deleted file mode 100644 index c7a017f1..00000000 --- a/conf/evolutions/default/82.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_admin_pin VARCHAR(10) NOT NULL DEFAULT(''); - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_admin_pin; diff --git a/conf/evolutions/default/83.sql b/conf/evolutions/default/83.sql deleted file mode 100644 index f1e4a59e..00000000 --- a/conf/evolutions/default/83.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE attendance_day ADD COLUMN off_campus_departure_time time; -ALTER TABLE attendance_day ADD COLUMN off_campus_return_time time; - -# --- !Downs - -ALTER TABLE attendance_day DROP COLUMN off_campus_departure_time; -ALTER TABLE attendance_day DROP COLUMN off_campus_return_time; diff --git a/conf/evolutions/default/84.sql b/conf/evolutions/default/84.sql deleted file mode 100644 index c57cd15d..00000000 --- a/conf/evolutions/default/84.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_enable_off_campus boolean NOT NULL DEFAULT(false); - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_enable_off_campus; \ No newline at end of file diff --git a/conf/evolutions/default/85.sql b/conf/evolutions/default/85.sql deleted file mode 100644 index 2ecd8e16..00000000 --- a/conf/evolutions/default/85.sql +++ /dev/null @@ -1,5 +0,0 @@ -# --- !Ups -ALTER TABLE account ADD COLUMN is_active boolean NOT NULL DEFAULT true; - -# --- !Downs -ALTER TABLE account DROP COLUMN is_active; diff --git a/conf/evolutions/default/86.sql b/conf/evolutions/default/86.sql deleted file mode 100644 index 5aed8ba6..00000000 --- a/conf/evolutions/default/86.sql +++ /dev/null @@ -1,5 +0,0 @@ -# --- !Ups -ALTER TABLE attendance_code ADD COLUMN not_counted boolean NOT NULL DEFAULT false; - -# --- !Downs -ALTER TABLE attendance_code DROP COLUMN not_counted; diff --git a/conf/evolutions/default/87.sql b/conf/evolutions/default/87.sql deleted file mode 100644 index 68d74001..00000000 --- a/conf/evolutions/default/87.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_show_reports boolean NOT NULL DEFAULT(false); -ALTER TABLE organization ADD COLUMN attendance_report_latest_departure_time time; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_show_reports; -ALTER TABLE organization DROP COLUMN attendance_report_latest_departure_time; \ No newline at end of file diff --git a/conf/evolutions/default/88.sql b/conf/evolutions/default/88.sql deleted file mode 100644 index 01ded2c7..00000000 --- a/conf/evolutions/default/88.sql +++ /dev/null @@ -1,18 +0,0 @@ -# --- !Ups - -DROP INDEX idx_entry_index; -DROP MATERIALIZED VIEW entry_index; - -CREATE MATERIALIZED VIEW entry_index AS -SELECT entry.id, - chapter.organization_id, - (to_tsvector(entry.content) || to_tsvector(entry.title) || - to_tsvector(CONCAT(chapter.num, section.num, '.', entry.num))) as document -FROM entry -JOIN section ON entry.section_id = section.id -JOIN chapter ON section.chapter_id = chapter.id -WHERE entry.deleted=false AND section.deleted=false AND chapter.deleted=false; - -CREATE INDEX idx_entry_index ON entry_index USING gin(document); - -# --- !Downs diff --git a/conf/evolutions/default/89.sql b/conf/evolutions/default/89.sql deleted file mode 100644 index 3e1f7969..00000000 --- a/conf/evolutions/default/89.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE attendance_day ADD COLUMN off_campus_minutes_exempted integer; - -# --- !Downs - -ALTER TABLE attendance_day DROP COLUMN off_campus_minutes_exempted; diff --git a/conf/evolutions/default/9.sql b/conf/evolutions/default/9.sql deleted file mode 100644 index e976ef6b..00000000 --- a/conf/evolutions/default/9.sql +++ /dev/null @@ -1,25 +0,0 @@ -# --- !Ups - -ALTER TABLE phone_numbers drop constraint fk_phone_numbers_person_1; -alter table phone_numbers add constraint fk_phone_numbers_person_1 foreign key (person_id) references person (person_id) on delete cascade on update restrict; - -ALTER TABLE person_tag drop constraint fk_person_tag_person_1; -alter table person_tag add constraint fk_person_tag_person_1 foreign key (person_id) references person (person_id) on delete cascade on update restrict; - -alter table person_tag drop constraint fk_person_tag_tag_1; -alter table person_tag add constraint fk_person_tag_tag_1 foreign key (tag_id) references tag (id) on delete cascade on update restrict; - -ALTER TABLE comments drop constraint fk_comments_person; -ALTER TABLE comments ADD constraint fk_comments_person foreign key (person_id) references person (person_id) on delete cascade on update restrict; - -ALTER TABLE completed_task drop constraint fk_completed_task_person; -ALTER TABLE completed_task ADD constraint fk_completed_task_person foreign key(person_id) references person (person_id) ON DELETE cascade ON UPDATE restrict; -ALTER TABLE completed_task drop constraint fk_completed_task_comment; -ALTER TABLE completed_task ADD constraint fk_completed_task_comment foreign key(comment_id) references comments(id) ON DELETE cascade ON UPDATE restrict; - -alter table person add column created timestamp default '2012-03-01'; -alter table person alter column created set default NOW(); - -# --- !Downs - -alter table person drop column created; diff --git a/conf/evolutions/default/90.sql b/conf/evolutions/default/90.sql deleted file mode 100644 index be9b14f6..00000000 --- a/conf/evolutions/default/90.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_rate_standard_time_frame integer; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_rate_standard_time_frame; diff --git a/conf/evolutions/default/91.sql b/conf/evolutions/default/91.sql deleted file mode 100644 index a324fe41..00000000 --- a/conf/evolutions/default/91.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ALTER COLUMN attendance_day_min_hours TYPE double precision; - -# --- !Downs - -ALTER TABLE organization ALTER COLUMN attendance_day_min_hours TYPE integer; \ No newline at end of file diff --git a/conf/evolutions/default/92.sql b/conf/evolutions/default/92.sql deleted file mode 100644 index 7f126563..00000000 --- a/conf/evolutions/default/92.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_report_late_fee integer; -ALTER TABLE organization ADD COLUMN attendance_report_late_fee_interval integer; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_report_late_fee; -ALTER TABLE organization DROP COLUMN attendance_report_late_fee_interval; diff --git a/conf/evolutions/default/93.sql b/conf/evolutions/default/93.sql deleted file mode 100644 index f5195ab4..00000000 --- a/conf/evolutions/default/93.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_show_weighted_percent boolean NOT NULL DEFAULT(false); -ALTER TABLE organization DROP COLUMN attendance_rate_standard_time_frame; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_show_weighted_percent; -ALTER TABLE organization ADD COLUMN attendance_rate_standard_time_frame integer; diff --git a/conf/evolutions/default/94.sql b/conf/evolutions/default/94.sql deleted file mode 100644 index ce6cdebe..00000000 --- a/conf/evolutions/default/94.sql +++ /dev/null @@ -1,26 +0,0 @@ -# --- !Ups - -CREATE TABLE attendance_rule ( - id serial, - organization_id integer NOT NULL, - category text, - person_id integer, - start_date date, - end_date date, - monday boolean NOT NULL, - tuesday boolean NOT NULL, - wednesday boolean NOT NULL, - thursday boolean NOT NULL, - friday boolean NOT NULL, - absence_code VARCHAR(64), - min_hours double precision, - latest_start_time time, - exempt_from_fees boolean NOT NULL, - CONSTRAINT pk_attendance_rule PRIMARY KEY(id), - CONSTRAINT fk_attendance_rule_organization FOREIGN KEY (organization_id) references organization(id), - CONSTRAINT fk_attendance_rule_person FOREIGN KEY (person_id) references person(person_id) -); - -# --- !Downs - -DROP TABLE attendance_rule; \ No newline at end of file diff --git a/conf/evolutions/default/95.sql b/conf/evolutions/default/95.sql deleted file mode 100644 index 287ead39..00000000 --- a/conf/evolutions/default/95.sql +++ /dev/null @@ -1,11 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_report_late_fee_2 integer; -ALTER TABLE organization ADD COLUMN attendance_report_late_fee_interval_2 integer; -ALTER TABLE organization ADD COLUMN attendance_report_latest_departure_time_2 time; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_report_late_fee_2; -ALTER TABLE organization DROP COLUMN attendance_report_late_fee_interval_2; -ALTER TABLE organization DROP COLUMN attendance_report_latest_departure_time_2; \ No newline at end of file diff --git a/conf/evolutions/default/96.sql b/conf/evolutions/default/96.sql deleted file mode 100644 index 8598e2b4..00000000 --- a/conf/evolutions/default/96.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_day_earliest_departure_time time; -ALTER TABLE attendance_rule ADD COLUMN earliest_departure_time time; - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_day_earliest_departure_time; -ALTER TABLE attendance_rule DROP COLUMN earliest_departure_time; \ No newline at end of file diff --git a/conf/evolutions/default/97.sql b/conf/evolutions/default/97.sql deleted file mode 100644 index 91e92505..00000000 --- a/conf/evolutions/default/97.sql +++ /dev/null @@ -1,9 +0,0 @@ -# --- !Ups - -ALTER TABLE tag ALTER COLUMN show_in_account_balances SET DEFAULT false; -ALTER TABLE tag ALTER COLUMN show_in_account_balances SET NOT NULL; - -# --- !Downs - -ALTER TABLE tag ALTER COLUMN show_in_account_balances DROP NOT NULL; -ALTER TABLE tag ALTER COLUMN show_in_account_balances DROP DEFAULT; diff --git a/conf/evolutions/default/98.sql b/conf/evolutions/default/98.sql deleted file mode 100644 index e0392ddf..00000000 --- a/conf/evolutions/default/98.sql +++ /dev/null @@ -1,52 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN show_roles boolean NOT NULL DEFAULT false; -ALTER TABLE organization ADD COLUMN roles_individual_term text DEFAULT 'Clerk'; -ALTER TABLE organization ADD COLUMN roles_committee_term text DEFAULT 'Committee'; -ALTER TABLE organization ADD COLUMN roles_group_term text DEFAULT 'Group'; - -ALTER TABLE tag ADD COLUMN show_in_roles boolean NOT NULL DEFAULT true; - -CREATE TABLE role ( - id serial, - organization_id integer NOT NULL, - is_active boolean NOT NULL DEFAULT true, - type integer NOT NULL, - eligibility integer NOT NULL, - name text NOT NULL, - notes text NOT NULL, - description text NOT NULL, - CONSTRAINT pk_role primary key(id), - CONSTRAINT fk_role_organization FOREIGN KEY (organization_id) REFERENCES organization(id) -); - -CREATE TABLE role_record ( - id serial, - role_id integer NOT NULL, - role_name text NOT NULL, - date_created timestamp NOT NULL, - CONSTRAINT pk_role_record primary key(id), - CONSTRAINT fk_role_record_role FOREIGN KEY (role_id) REFERENCES role(id) -); - -CREATE TABLE role_record_member ( - record_id integer NOT NULL, - person_id integer, - person_name text, - type integer NOT NULL, - CONSTRAINT fk_role_record_member_record FOREIGN KEY (record_id) REFERENCES role_record(id), - CONSTRAINT fk_role_record_member_person FOREIGN KEY (person_id) REFERENCES person(person_id) -); - -# --- !Downs - -DROP TABLE role_record_member; -DROP TABLE role_record; -DROP TABLE role; - -ALTER TABLE organization DROP COLUMN roles_individual_term; -ALTER TABLE organization DROP COLUMN roles_committee_term; -ALTER TABLE organization DROP COLUMN roles_group_term; -ALTER TABLE organization DROP COLUMN show_roles; - -ALTER TABLE tag DROP COLUMN show_in_roles; \ No newline at end of file diff --git a/conf/evolutions/default/99.sql b/conf/evolutions/default/99.sql deleted file mode 100644 index 65dd5c20..00000000 --- a/conf/evolutions/default/99.sql +++ /dev/null @@ -1,7 +0,0 @@ -# --- !Ups - -ALTER TABLE organization ADD COLUMN attendance_show_rate_in_checkin boolean NOT NULL DEFAULT(false); - -# --- !Downs - -ALTER TABLE organization DROP COLUMN attendance_show_rate_in_checkin; diff --git a/conf/production.conf b/conf/production.conf index c52da545..d250202f 100644 --- a/conf/production.conf +++ b/conf/production.conf @@ -1,7 +1,5 @@ include "base.conf" -play.evolutions.db.default.autoApply=true - school_crm { heroku_ips = true shared_files_path = "/www-dst" diff --git a/data_conversion/migrate_custodia_to_django.sql b/data_conversion/migrate_custodia_to_django.sql deleted file mode 100644 index ebda1010..00000000 --- a/data_conversion/migrate_custodia_to_django.sql +++ /dev/null @@ -1,150 +0,0 @@ --- This script takes the database that was created by the old Custodia --- Clojure code and its migrations and converts it to match the initial --- state of the Django Custodia models (what is generated by --- django/custodia/migrations/0001_initial.py) --- --- If you never did local development of Custodia with the Clojure code, --- you won't need to run this. - - -\set ON_ERROR_STOP 1 - -BEGIN; - --- Copy over columns from overseer.students to person -UPDATE person p set custodia_show_as_absent=s.show_as_absent - FROM overseer.students s where s.dst_id=p.person_id; -UPDATE person p set custodia_start_date=s.start_date - FROM overseer.students s where s.dst_id=p.person_id; - - - -alter table overseer.excuses add column person_id int4 null; -ALTER TABLE overseer.excuses ADD CONSTRAINT fk_excuses_person FOREIGN KEY (person_id) REFERENCES public.person(person_id); -alter table overseer.swipes add column person_id int4 null; -ALTER TABLE overseer.swipes ADD CONSTRAINT fk_person FOREIGN KEY (person_id) REFERENCES public.person(person_id); -alter table overseer.students_required_minutes add column person_id int4 null; -ALTER TABLE overseer.students_required_minutes ADD CONSTRAINT fk_person FOREIGN KEY (person_id) REFERENCES public.person(person_id); -alter table overseer.overrides add column person_id int4 null; -ALTER TABLE overseer.overrides ADD CONSTRAINT fk_person FOREIGN KEY (person_id) REFERENCES public.person(person_id); - -UPDATE overseer.excuses e set person_id=s.dst_id - FROM overseer.students s, public.person p where s._id=e.student_id and s.dst_id=p.person_id; -delete FROM overseer.excuses where person_id is null; -UPDATE overseer.swipes e set person_id=s.dst_id - FROM overseer.students s, public.person p where s._id=e.student_id and s.dst_id=p.person_id; -delete FROM overseer.swipes where person_id is null; -UPDATE overseer.students_required_minutes e set person_id=s.dst_id - FROM overseer.students s, public.person p where s._id=e.student_id and s.dst_id=p.person_id; -delete FROM overseer.students_required_minutes where person_id is null; -UPDATE overseer.overrides e set person_id=s.dst_id - FROM overseer.students s, public.person p where s._id=e.student_id and s.dst_id=p.person_id; -delete FROM overseer.overrides where person_id is null; - -alter table overseer.excuses alter column person_id set not null; -alter table overseer.swipes alter column person_id set not null; -alter table overseer.students_required_minutes alter column person_id set not null; -alter table overseer.overrides alter column person_id set not null; - - -DELETE FROM overseer.excuses a USING ( - SELECT MIN(ctid) as ctid, person_id, "date" - FROM overseer.excuses - GROUP BY person_id, "date" HAVING COUNT(*) > 1 -) b -WHERE a.person_id = b.person_id and a.date=b.date -AND a.ctid <> b.ctid; -alter table overseer.excuses add constraint uniq_excuses_person_date unique(person_id, "date"); - -DELETE FROM overseer.overrides a USING ( - SELECT MIN(ctid) as ctid, person_id, "date" - FROM overseer.overrides - GROUP BY person_id, "date" HAVING COUNT(*) > 1 -) b -WHERE a.person_id = b.person_id and a.date=b.date -AND a.ctid <> b.ctid; -alter table overseer.overrides add constraint uniq_overrides_person_date unique(person_id, "date"); - -alter table overseer.swipes drop column rounded_in_time; -alter table overseer.swipes drop column rounded_out_time; -alter table overseer.swipes drop column intervalmin; -create index on overseer.swipes (person_id, swipe_day); -create index on overseer.swipes (swipe_day, person_id); -alter table overseer.swipes alter column swipe_day set not null; - -alter table overseer.excuses drop column student_id; -alter table overseer.swipes drop column student_id cascade; -alter table overseer.students_required_minutes drop column student_id cascade; -alter table overseer.overrides drop column student_id; - - --- Combine overseer.schools with public.organization, and fix a bunch of things --- about the years table. - -UPDATE organization o set timezone=s.timezone FROM overseer.schools s where s._id=o.id; - -ALTER TABLE overseer.years RENAME COLUMN school_id to organization_id; -ALTER TABLE overseer.years DROP CONSTRAINT fk_class_school; -ALTER TABLE overseer.years ADD CONSTRAINT fk_org FOREIGN KEY (organization_id) REFERENCES organization(id); -ALTER TABLE overseer.years ALTER COLUMN organization_id DROP DEFAULT; -ALTER TABLE overseer.years ALTER COLUMN name SET NOT NULL; - -ALTER TABLE overseer.years ALTER COLUMN inserted_date SET NOT NULL; -ALTER TABLE overseer.years ALTER COLUMN inserted_date DROP DEFAULT; -ALTER TABLE overseer.years ALTER COLUMN inserted_date type timestamp with time zone; - -ALTER TABLE overseer.excuses ALTER COLUMN inserted_date SET NOT NULL; -ALTER TABLE overseer.excuses ALTER COLUMN "date" SET NOT NULL; -ALTER TABLE overseer.excuses ALTER COLUMN inserted_date DROP DEFAULT; -ALTER TABLE overseer.excuses ALTER COLUMN inserted_date type timestamp with time zone; - -ALTER TABLE overseer.overrides ALTER COLUMN inserted_date SET NOT NULL; -ALTER TABLE overseer.overrides ALTER COLUMN "date" SET NOT NULL; -ALTER TABLE overseer.overrides ALTER COLUMN inserted_date DROP DEFAULT; -ALTER TABLE overseer.overrides ALTER COLUMN inserted_date type timestamp with time zone; - -delete from overseer.years where from_date is null or to_date is null; -ALTER TABLE overseer.years ALTER COLUMN from_date SET NOT NULL; -ALTER TABLE overseer.years ALTER COLUMN to_date SET NOT NULL; - -ALTER TABLE overseer.years RENAME COLUMN from_date to from_time; -ALTER TABLE overseer.years RENAME COLUMN to_date to to_time; - - --- Delete duplicate organization_id, name -DELETE FROM overseer.years a USING ( - SELECT MIN(ctid) as ctid, organization_id, name - FROM overseer.years - GROUP BY organization_id, name HAVING COUNT(*) > 1 -) b -WHERE a.organization_id = b.organization_id and a.name=b.name -AND a.ctid <> b.ctid; -ALTER TABLE overseer.years ADD CONSTRAINT unique_name UNIQUE (organization_id, name); - --- Add unique ID to students_required_minutes table -ALTER TABLE overseer.students_required_minutes ADD COLUMN id SERIAL PRIMARY KEY; - --- Disallow null in times for swipes -DELETE FROM overseer.swipes WHERE in_time is NULL; -ALTER TABLE overseer.swipes ALTER COLUMN in_time SET NOT NULL; - - --- Move tables that we are saving out of overseer schema and rename to Django-style names -ALTER TABLE overseer.students_required_minutes set schema public; -ALTER TABLE overseer.swipes set schema public; -ALTER TABLE overseer.overrides set schema public; -ALTER TABLE overseer.excuses set schema public; -ALTER TABLE overseer.years set schema public; - -ALTER TABLE swipes RENAME COLUMN _id to id; -ALTER TABLE overrides RENAME COLUMN _id to id; -ALTER TABLE excuses RENAME COLUMN _id to id; -ALTER TABLE years RENAME COLUMN _id to id; - -ALTER TABLE students_required_minutes RENAME TO custodia_studentrequiredminutes; -ALTER TABLE swipes RENAME TO custodia_swipe; -ALTER TABLE overrides RENAME TO custodia_override; -ALTER TABLE excuses RENAME TO custodia_excuse; -ALTER TABLE years RENAME TO custodia_year; - -COMMIT; \ No newline at end of file diff --git a/data_conversion/test_migrate_custodia.sh b/data_conversion/test_migrate_custodia.sh deleted file mode 100755 index 5140fc93..00000000 --- a/data_conversion/test_migrate_custodia.sh +++ /dev/null @@ -1,25 +0,0 @@ -set -ex - -psql << 'EOF' -\set ON_ERROR_STOP 1 -DROP DATABASE IF EXISTS school_crm; -CREATE DATABASE school_crm; -DROP ROLE IF EXISTS custodia; -EOF - -psql school_crm < ~/dump-school_crm-202502221543.sql - -# Apply all the ups from this migration -grep --before-context 1000 '!Downs' ../conf/evolutions/default/101.sql | grep -v '\-\-\-' - | psql school_crm - -psql school_crm < ../data_conversion/migrate_custodia_to_django.sql - -psql school_crm << 'EOF' -\set ON_ERROR_STOP 1 -INSERT INTO organization_hosts(host, organization_id) - VALUES ('localhost:9000', 2) ON CONFLICT DO NOTHING; -UPDATE users set is_staff=true, is_superuser=true where organization_id is null; -EOF - -uv run manage.py migrate custodia --fake -uv run manage.py migrate diff --git a/django/custodia/migrations/0003_swipe_person_swipe_day_empty_out_unique.py b/django/custodia/migrations/0003_swipe_person_swipe_day_empty_out_unique.py new file mode 100644 index 00000000..41dcf0b5 --- /dev/null +++ b/django/custodia/migrations/0003_swipe_person_swipe_day_empty_out_unique.py @@ -0,0 +1,22 @@ +# Generated by Django 5.1.6 on 2025-10-02 00:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("custodia", "0002_auto_20250226_2043"), + ("dst", "0001_initial"), + ] + + operations = [ + migrations.AddConstraint( + model_name="swipe", + constraint=models.UniqueConstraint( + models.F("person"), + models.F("swipe_day"), + condition=models.Q(("out_time", None)), + name="person_swipe_day_empty_out_unique", + ), + ), + ] diff --git a/django/dst/management/commands/setup_initial_data.py b/django/dst/management/commands/setup_initial_data.py new file mode 100644 index 00000000..6377f41f --- /dev/null +++ b/django/dst/management/commands/setup_initial_data.py @@ -0,0 +1,62 @@ +""" +uv run manage.py setup_initial_data +""" + +from django.core.management.base import BaseCommand +from django.db.transaction import atomic + +from dst.models import ( + Organization, + OrganizationHost, + Tag, + User, + UserRole, +) + + +class Command(BaseCommand): + help = "Create some initial data for local development" + + @atomic + def handle(self, *args, **kwargs): + org = Organization.objects.create( + short_name="Sandbox", + name="DemSchoolTools sandbox area", + show_custodia=True, + show_accounting=True, + enable_case_references=True, + show_electronic_signin=True, + show_roles=True, + ) + + OrganizationHost.objects.create(host="localhost:9000", organization=org) + + Tag.objects.create( + title="Current Student", + use_student_display=True, + organization=org, + show_in_jc=True, + show_in_attendance=True, + show_in_account_balances=True, + show_in_roles=True, + ) + Tag.objects.create( + title="Staff", + use_student_display=False, + organization=org, + show_in_jc=True, + show_in_attendance=True, + show_in_account_balances=True, + show_in_roles=True, + ) + + user = User.objects.create( + email="admin@asdf.com", + name="Admin User", + email_validated=True, + is_staff=True, + is_superuser=True, + password="$2a$10$sHAtPc.yeZg2AWMr7EZZbuu.sYaOPgFsMZiAY62q/URbjMxU3jB.q", + ) + + UserRole.objects.create(user=user, role=UserRole.ALL_ACCESS) diff --git a/django/dst/migrations/0001_initial.py b/django/dst/migrations/0001_initial.py new file mode 100644 index 00000000..03ff17db --- /dev/null +++ b/django/dst/migrations/0001_initial.py @@ -0,0 +1,1647 @@ +# Generated by Django 5.1.6 on 2025-10-02 13:21 + +from decimal import Decimal + +import django.contrib.auth.models +import django.contrib.auth.validators +import django.db.models.deletion +import django.db.models.functions.datetime +import django.utils.timezone +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Case", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("case_number", models.CharField(default="", max_length=255)), + ("findings", models.TextField(default="")), + ("date", models.DateField(blank=True, null=True)), + ("location", models.CharField(default="", max_length=255)), + ("time", models.CharField(default="", max_length=255)), + ("date_closed", models.DateField(blank=True, null=True)), + ], + options={ + "db_table": "case", + }, + ), + migrations.CreateModel( + name="Entry", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.TextField()), + ("num", models.TextField()), + ("deleted", models.BooleanField(default=False)), + ("content", models.TextField()), + ("is_breaking_res_plan", models.BooleanField(default=False)), + ], + options={ + "db_table": "entry", + }, + ), + migrations.CreateModel( + name="Meeting", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("date", models.DateField()), + ], + options={ + "db_table": "meeting", + }, + ), + migrations.CreateModel( + name="Organization", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.TextField()), + ("short_name", models.TextField(blank=True, default="")), + ("timezone", models.TextField(default="America/New_York")), + ("late_time", models.TimeField(blank=True, null=True)), + ("printer_email", models.TextField(blank=True, default="")), + ("mailchimp_api_key", models.TextField(blank=True, default="")), + ( + "mailchimp_last_sync_person_changes", + models.DateTimeField(blank=True, null=True), + ), + ("mailchimp_updates_email", models.TextField(blank=True, default="")), + ("jc_reset_day", models.IntegerField(default=3)), + ("show_last_modified_in_print", models.BooleanField(default=True)), + ("show_history_in_print", models.BooleanField(default=True)), + ("show_custodia", models.BooleanField(default=False)), + ("show_attendance", models.BooleanField(default=True)), + ("show_electronic_signin", models.BooleanField(default=False)), + ("show_accounting", models.BooleanField(default=False)), + ("show_roles", models.BooleanField(default=False)), + ("enable_case_references", models.BooleanField(default=False)), + ("attendance_enable_off_campus", models.BooleanField(default=False)), + ("attendance_show_reports", models.BooleanField(default=False)), + ( + "attendance_report_latest_departure_time", + models.TimeField(blank=True, null=True), + ), + ( + "attendance_report_latest_departure_time_2", + models.TimeField(blank=True, null=True), + ), + ( + "attendance_day_earliest_departure_time", + models.TimeField(blank=True, null=True), + ), + ( + "attendance_report_late_fee", + models.IntegerField(blank=True, null=True), + ), + ( + "attendance_report_late_fee_2", + models.IntegerField(blank=True, null=True), + ), + ( + "attendance_report_late_fee_interval", + models.IntegerField(blank=True, null=True), + ), + ( + "attendance_report_late_fee_interval_2", + models.IntegerField(blank=True, null=True), + ), + ("attendance_show_percent", models.BooleanField(default=False)), + ( + "attendance_show_weighted_percent", + models.BooleanField(default=False), + ), + ("attendance_show_rate_in_checkin", models.BooleanField(default=False)), + ("attendance_enable_partial_days", models.BooleanField(default=False)), + ( + "attendance_day_latest_start_time", + models.TimeField(blank=True, null=True), + ), + ("attendance_day_min_hours", models.FloatField(blank=True, null=True)), + ( + "attendance_partial_day_value", + models.DecimalField( + blank=True, decimal_places=2, max_digits=10, null=True + ), + ), + ( + "attendance_admin_pin", + models.CharField(blank=True, default="", max_length=10), + ), + ( + "attendance_default_absence_code", + models.TextField(blank=True, null=True), + ), + ( + "attendance_default_absence_code_time", + models.TimeField(blank=True, null=True), + ), + ( + "roles_individual_term", + models.TextField(blank=True, default="Clerk", null=True), + ), + ( + "roles_committee_term", + models.TextField(blank=True, default="Committee", null=True), + ), + ( + "roles_group_term", + models.TextField(blank=True, default="Group", null=True), + ), + ("custodia_password", models.TextField(blank=True, default="")), + ], + options={ + "db_table": "organization", + }, + ), + migrations.CreateModel( + name="Task", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(blank=True, max_length=255, null=True)), + ("sort_order", models.IntegerField(blank=True, null=True)), + ("enabled", models.BooleanField(blank=True, null=True)), + ], + options={ + "db_table": "task", + }, + ), + migrations.CreateModel( + name="CaseMeeting", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "case", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="dst.case" + ), + ), + ( + "meeting", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="dst.meeting" + ), + ), + ], + options={ + "db_table": "case_meeting", + }, + ), + migrations.AddField( + model_name="case", + name="meeting", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.meeting" + ), + ), + migrations.AddField( + model_name="case", + name="meetings", + field=models.ManyToManyField( + related_name="cases_many", through="dst.CaseMeeting", to="dst.meeting" + ), + ), + migrations.AddField( + model_name="meeting", + name="organization", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.organization" + ), + ), + migrations.CreateModel( + name="Email", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("message", models.TextField(blank=True, null=True)), + ("sent", models.BooleanField()), + ("deleted", models.BooleanField()), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": "email", + }, + ), + migrations.CreateModel( + name="Chapter", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.TextField()), + ("num", models.TextField()), + ("deleted", models.BooleanField(default=False)), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": "chapter", + }, + ), + migrations.CreateModel( + name="AttendanceCode", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("code", models.CharField(max_length=64)), + ("description", models.TextField()), + ("color", models.CharField(max_length=16)), + ("counts_toward_attendance", models.BooleanField(default=False)), + ("not_counted", models.BooleanField(default=False)), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": "attendance_code", + }, + ), + migrations.CreateModel( + name="AllowedIp", + fields=[ + ("ip", models.TextField(primary_key=True, serialize=False)), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": "allowed_ips", + }, + ), + migrations.CreateModel( + name="User", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "last_login", + models.DateTimeField( + blank=True, null=True, verbose_name="last login" + ), + ), + ( + "is_superuser", + models.BooleanField( + default=False, + help_text="Designates that this user has all permissions without explicitly assigning them.", + verbose_name="superuser status", + ), + ), + ( + "username", + models.CharField( + error_messages={ + "unique": "A user with that username already exists." + }, + help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.", + max_length=150, + unique=True, + validators=[ + django.contrib.auth.validators.UnicodeUsernameValidator() + ], + verbose_name="username", + ), + ), + ( + "first_name", + models.CharField( + blank=True, max_length=150, verbose_name="first name" + ), + ), + ( + "last_name", + models.CharField( + blank=True, max_length=150, verbose_name="last name" + ), + ), + ( + "is_staff", + models.BooleanField( + default=False, + help_text="Designates whether the user can log into this admin site.", + verbose_name="staff status", + ), + ), + ( + "date_joined", + models.DateTimeField( + default=django.utils.timezone.now, verbose_name="date joined" + ), + ), + ("password", models.TextField(db_column="hashed_password")), + ("is_active", models.BooleanField(db_column="active", default=True)), + ("name", models.TextField()), + ("email", models.TextField()), + ("email_validated", models.BooleanField(default=False)), + ( + "organization", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": 'public"."users', + }, + managers=[ + ("objects", django.contrib.auth.models.UserManager()), + ], + ), + migrations.CreateModel( + name="OrganizationHost", + fields=[ + ("host", models.TextField(primary_key=True, serialize=False)), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="hosts", + to="dst.organization", + ), + ), + ], + options={ + "db_table": "organization_hosts", + }, + ), + migrations.CreateModel( + name="Person", + fields=[ + ("first_name", models.CharField(default="", max_length=255)), + ("last_name", models.CharField(default="", max_length=255)), + ("display_name", models.CharField(default="", max_length=255)), + ("is_family", models.BooleanField(default=False)), + ("email", models.CharField(blank=True, default="", max_length=255)), + ("address", models.CharField(blank=True, default="", max_length=255)), + ("city", models.CharField(blank=True, default="", max_length=255)), + ("state", models.CharField(blank=True, default="", max_length=255)), + ("zip", models.CharField(blank=True, default="", max_length=255)), + ( + "neighborhood", + models.CharField(blank=True, default="", max_length=255), + ), + ("gender", models.TextField(default="Unknown")), + ("dob", models.DateField(blank=True, null=True)), + ("approximate_dob", models.DateField(blank=True, null=True)), + ("grade", models.TextField(blank=True, default="")), + ("notes", models.TextField(blank=True, default="")), + ("previous_school", models.CharField(default="", max_length=255)), + ("school_district", models.CharField(default="", max_length=255)), + ( + "id", + models.AutoField( + db_column="person_id", primary_key=True, serialize=False + ), + ), + ( + "created", + models.DateTimeField( + db_default=django.db.models.functions.datetime.Now() + ), + ), + ("pin", models.CharField(blank=True, default="", max_length=10)), + ("custodia_show_as_absent", models.DateField(blank=True, null=True)), + ("custodia_start_date", models.DateField(blank=True, null=True)), + ( + "family_person", + models.ForeignKey( + blank=True, + db_column="family_person_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.person", + ), + ), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": "person", + }, + ), + migrations.CreateModel( + name="Donation", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("dollar_value", models.FloatField(blank=True, null=True)), + ("is_cash", models.BooleanField()), + ("description", models.TextField()), + ( + "date", + models.DateTimeField( + db_default=django.db.models.functions.datetime.Now() + ), + ), + ("thanked", models.BooleanField()), + ("thanked_time", models.DateTimeField(blank=True, null=True)), + ("indiegogo_reward_given", models.BooleanField()), + ( + "indiegogo_reward_given_time", + models.DateTimeField(blank=True, null=True), + ), + ( + "indiegogo_reward_by_user", + models.ForeignKey( + blank=True, + db_column="indiegogo_reward_by_user_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="donations_indiegogo_rewarded", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "thanked_by_user", + models.ForeignKey( + blank=True, + db_column="thanked_by_user_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="donations_thanked", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="dst.person" + ), + ), + ], + options={ + "db_table": "donation", + }, + ), + migrations.CreateModel( + name="Comment", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("message", models.TextField(blank=True, null=True)), + ( + "created", + models.DateTimeField( + db_default=django.db.models.functions.datetime.Now() + ), + ), + ( + "user", + models.ForeignKey( + db_column="user_id", + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="dst.person" + ), + ), + ], + options={ + "db_table": "comments", + }, + ), + migrations.CreateModel( + name="Charge", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("plea", models.CharField(default="", max_length=255)), + ("resolution_plan", models.TextField(default="")), + ("referred_to_sm", models.BooleanField(default=False)), + ("sm_decision", models.TextField(blank=True, null=True)), + ("sm_decision_date", models.DateField(blank=True, null=True)), + ( + "minor_referral_destination", + models.CharField(default="", max_length=255), + ), + ("severity", models.CharField(default="", max_length=255)), + ("rp_complete", models.BooleanField(default=False)), + ("rp_complete_date", models.DateTimeField(blank=True, null=True)), + ( + "case", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.case" + ), + ), + ( + "referenced_charge", + models.ForeignKey( + blank=True, + db_column="referenced_charge_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.charge", + ), + ), + ( + "rule", + models.ForeignKey( + blank=True, + db_column="rule_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.entry", + ), + ), + ( + "person", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.person", + ), + ), + ], + options={ + "db_table": "charge", + }, + ), + migrations.CreateModel( + name="AttendanceWeek", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("monday", models.DateField()), + ("extra_hours", models.FloatField(default=0)), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.person" + ), + ), + ], + options={ + "db_table": "attendance_week", + }, + ), + migrations.CreateModel( + name="AttendanceRule", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("category", models.TextField(blank=True, null=True)), + ("start_date", models.DateField(blank=True, null=True)), + ("end_date", models.DateField(blank=True, null=True)), + ("monday", models.BooleanField()), + ("tuesday", models.BooleanField()), + ("wednesday", models.BooleanField()), + ("thursday", models.BooleanField()), + ("friday", models.BooleanField()), + ( + "absence_code", + models.CharField(blank=True, max_length=64, null=True), + ), + ("min_hours", models.FloatField(blank=True, null=True)), + ("latest_start_time", models.TimeField(blank=True, null=True)), + ("earliest_departure_time", models.TimeField(blank=True, null=True)), + ("exempt_from_fees", models.BooleanField()), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ( + "person", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.person", + ), + ), + ], + options={ + "db_table": "attendance_rule", + }, + ), + migrations.CreateModel( + name="AttendanceDay", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("day", models.DateField()), + ("code", models.CharField(blank=True, max_length=64, null=True)), + ("start_time", models.TimeField(blank=True, null=True)), + ("end_time", models.TimeField(blank=True, null=True)), + ("off_campus_departure_time", models.TimeField(blank=True, null=True)), + ("off_campus_return_time", models.TimeField(blank=True, null=True)), + ( + "off_campus_minutes_exempted", + models.IntegerField(blank=True, null=True), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.person" + ), + ), + ], + options={ + "db_table": "attendance_day", + }, + ), + migrations.CreateModel( + name="Account", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("type", models.IntegerField()), + ( + "initial_balance", + models.DecimalField(decimal_places=2, max_digits=10), + ), + ("name", models.TextField(default="")), + ( + "monthly_credit", + models.DecimalField( + decimal_places=2, default=Decimal("0"), max_digits=10 + ), + ), + ( + "date_last_monthly_credit", + models.DateTimeField(blank=True, null=True), + ), + ("is_active", models.BooleanField(default=True)), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ( + "person", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.person", + ), + ), + ], + options={ + "db_table": "account", + }, + ), + migrations.CreateModel( + name="PersonAtCase", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("role", models.IntegerField(default=0)), + ( + "case", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.case", + ), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.person" + ), + ), + ], + options={ + "db_table": "person_at_case", + }, + ), + migrations.CreateModel( + name="PersonAtMeeting", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("role", models.IntegerField(blank=True, null=True)), + ( + "meeting", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.meeting", + ), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.person" + ), + ), + ], + options={ + "db_table": "person_at_meeting", + }, + ), + migrations.CreateModel( + name="PersonChange", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("old_email", models.CharField(max_length=255)), + ("new_email", models.CharField(max_length=255)), + ( + "time", + models.DateTimeField( + db_default=django.db.models.functions.datetime.Now() + ), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.person" + ), + ), + ], + options={ + "db_table": "person_change", + }, + ), + migrations.CreateModel( + name="PhoneNumber", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("comment", models.CharField(blank=True, max_length=255, null=True)), + ("number", models.CharField(blank=True, max_length=255, null=True)), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="dst.person" + ), + ), + ], + options={ + "db_table": "phone_numbers", + }, + ), + migrations.CreateModel( + name="Role", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("is_active", models.BooleanField(default=True)), + ("type", models.IntegerField()), + ("eligibility", models.IntegerField()), + ("name", models.TextField()), + ("notes", models.TextField()), + ("description", models.TextField()), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": "role", + }, + ), + migrations.CreateModel( + name="RoleRecord", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("role_name", models.TextField()), + ("date_created", models.DateTimeField()), + ( + "role", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.role" + ), + ), + ], + options={ + "db_table": "role_record", + }, + ), + migrations.CreateModel( + name="RoleRecordMember", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("person_name", models.TextField(blank=True, null=True)), + ("type", models.IntegerField()), + ( + "person", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.person", + ), + ), + ( + "role_record", + models.ForeignKey( + db_column="record_id", + on_delete=django.db.models.deletion.PROTECT, + to="dst.rolerecord", + ), + ), + ], + options={ + "db_table": "role_record_member", + }, + ), + migrations.CreateModel( + name="Section", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.TextField()), + ("num", models.TextField()), + ("deleted", models.BooleanField(default=False)), + ( + "chapter", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="sections", + to="dst.chapter", + ), + ), + ], + options={ + "db_table": "section", + }, + ), + migrations.CreateModel( + name="ManualChange", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "date_entered", + models.DateTimeField( + db_default=django.db.models.functions.datetime.Now() + ), + ), + ("effective_date", models.DateField(blank=True, null=True)), + ("show_date_in_history", models.BooleanField(default=True)), + ("was_deleted", models.BooleanField(default=False)), + ("was_created", models.BooleanField(default=False)), + ("old_content", models.TextField(blank=True, null=True)), + ("new_content", models.TextField(blank=True, null=True)), + ("old_title", models.CharField(blank=True, max_length=255, null=True)), + ("new_title", models.CharField(blank=True, max_length=255, null=True)), + ("old_num", models.TextField(blank=True, null=True)), + ("new_num", models.TextField(blank=True, null=True)), + ( + "chapter", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="changes", + to="dst.chapter", + ), + ), + ( + "entry", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="changes", + to="dst.entry", + ), + ), + ( + "user", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "section", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="changes", + to="dst.section", + ), + ), + ], + options={ + "db_table": "manual_change", + }, + ), + migrations.AddField( + model_name="entry", + name="section", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="entries", + to="dst.section", + ), + ), + migrations.CreateModel( + name="Tag", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.TextField()), + ("use_student_display", models.BooleanField(default=False)), + ("show_in_jc", models.BooleanField(default=False)), + ("show_in_attendance", models.BooleanField(default=False)), + ("show_in_menu", models.BooleanField(default=True)), + ("show_in_account_balances", models.BooleanField(default=False)), + ("show_in_roles", models.BooleanField(default=True)), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ], + options={ + "db_table": "tag", + }, + ), + migrations.CreateModel( + name="PersonTagChange", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "time", + models.DateTimeField( + db_default=django.db.models.functions.datetime.Now() + ), + ), + ("was_add", models.BooleanField()), + ( + "creator", + models.ForeignKey( + db_column="creator_id", + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.person" + ), + ), + ( + "tag", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.tag" + ), + ), + ], + options={ + "db_table": "person_tag_change", + }, + ), + migrations.AddField( + model_name="person", + name="tags", + field=models.ManyToManyField( + blank=True, db_table="person_tag", to="dst.tag" + ), + ), + migrations.CreateModel( + name="NotificationRule", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("the_type", models.IntegerField()), + ("email", models.TextField()), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ( + "tag", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.tag", + ), + ), + ], + options={ + "db_table": "notification_rule", + }, + ), + migrations.CreateModel( + name="MailchimpSync", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("mailchimp_list_id", models.CharField(max_length=255)), + ("sync_local_adds", models.BooleanField()), + ("sync_local_removes", models.BooleanField()), + ("last_sync", models.DateTimeField(blank=True, null=True)), + ( + "tag", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.tag" + ), + ), + ], + options={ + "db_table": "mailchimp_sync", + }, + ), + migrations.CreateModel( + name="CompletedTask", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "comment", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="dst.comment", + ), + ), + ( + "person", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="dst.person" + ), + ), + ( + "task", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="dst.task" + ), + ), + ], + options={ + "db_table": "completed_task", + }, + ), + migrations.CreateModel( + name="TaskList", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(blank=True, max_length=255, null=True)), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ( + "tag", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.tag", + ), + ), + ], + options={ + "db_table": "task_list", + }, + ), + migrations.AddField( + model_name="task", + name="task_list", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="dst.tasklist", + ), + ), + migrations.CreateModel( + name="Transaction", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("from_name", models.TextField()), + ("to_name", models.TextField()), + ("description", models.TextField()), + ("type", models.IntegerField()), + ("amount", models.DecimalField(decimal_places=2, max_digits=10)), + ("date_created", models.DateTimeField()), + ("archived", models.BooleanField(default=False)), + ( + "created_by_user", + models.ForeignKey( + blank=True, + db_column="created_by_user_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "from_account", + models.ForeignKey( + blank=True, + db_column="from_account_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="transactions_from", + to="dst.account", + ), + ), + ( + "organization", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="dst.organization", + ), + ), + ( + "to_account", + models.ForeignKey( + blank=True, + db_column="to_account_id", + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="transactions_to", + to="dst.account", + ), + ), + ], + options={ + "db_table": "transactions", + }, + ), + migrations.CreateModel( + name="UserRole", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("role", models.TextField()), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="roles", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "db_table": 'public"."user_role', + }, + ), + migrations.CreateModel( + name="CaseReference", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "referenced_case", + models.ForeignKey( + db_column="referenced_case", + on_delete=django.db.models.deletion.PROTECT, + to="dst.case", + ), + ), + ( + "referencing_case", + models.ForeignKey( + db_column="referencing_case", + on_delete=django.db.models.deletion.PROTECT, + related_name="case_reference_cases", + to="dst.case", + ), + ), + ], + options={ + "db_table": "case_reference", + "constraints": [ + models.UniqueConstraint( + fields=("referenced_case", "referencing_case"), + name="uk_case_case", + ) + ], + }, + ), + migrations.CreateModel( + name="ChargeReference", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "referenced_charge", + models.ForeignKey( + db_column="referenced_charge", + on_delete=django.db.models.deletion.PROTECT, + to="dst.charge", + ), + ), + ( + "referencing_case", + models.ForeignKey( + db_column="referencing_case", + on_delete=django.db.models.deletion.PROTECT, + to="dst.case", + ), + ), + ], + options={ + "db_table": "charge_reference", + "constraints": [ + models.UniqueConstraint( + fields=("referenced_charge", "referencing_case"), + name="uk_charge_case", + ) + ], + }, + ), + migrations.CreateModel( + name="LinkedAccount", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("provider_user_id", models.TextField()), + ("provider_key", models.TextField()), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="linked_accounts", + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "db_table": 'public"."linked_account', + "constraints": [ + models.UniqueConstraint( + fields=("provider_key", "provider_user_id"), + name="u_linked_account", + ) + ], + }, + ), + migrations.AddConstraint( + model_name="case", + constraint=models.UniqueConstraint( + fields=("case_number", "meeting"), name="u_case_number_meeting" + ), + ), + migrations.AddConstraint( + model_name="meeting", + constraint=models.UniqueConstraint( + fields=("organization", "date"), name="unq_org_date" + ), + ), + migrations.AddConstraint( + model_name="user", + constraint=models.UniqueConstraint( + fields=("email",), name="users_unique_email_1" + ), + ), + migrations.AddIndex( + model_name="attendanceweek", + index=models.Index(fields=["monday"], name="attendance_week_monday_idx"), + ), + migrations.AddConstraint( + model_name="attendanceweek", + constraint=models.UniqueConstraint( + fields=("person", "monday"), name="u_attendance_week" + ), + ), + migrations.AddIndex( + model_name="attendanceday", + index=models.Index(fields=["day"], name="attendance_day_day_idx"), + ), + migrations.AddConstraint( + model_name="attendanceday", + constraint=models.UniqueConstraint( + fields=("person", "day"), name="u_attendance_day" + ), + ), + migrations.AddConstraint( + model_name="tag", + constraint=models.UniqueConstraint( + fields=("title", "organization"), name="unique_title_org" + ), + ), + migrations.AddConstraint( + model_name="completedtask", + constraint=models.UniqueConstraint( + fields=("task", "person"), name="unique_completed_task_1" + ), + ), + ] diff --git a/django/dst/migrations/__init__.py b/django/dst/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/django/dst/models.py b/django/dst/models.py index 9efd1873..7f117f47 100644 --- a/django/dst/models.py +++ b/django/dst/models.py @@ -1,7 +1,9 @@ from datetime import date +from decimal import Decimal from django.contrib.auth.models import AbstractUser from django.db import models +from django.db.models.functions import Now class Organization(models.Model): @@ -10,24 +12,35 @@ class Meta: id: int name = models.TextField() - short_name = models.TextField() - timezone = models.TextField() - late_time = models.TimeField() - - printer_email = models.TextField(null=True, blank=True) - jc_reset_day = models.IntegerField(null=True, blank=True) - show_last_modified_in_print = models.BooleanField(default=False) - show_history_in_print = models.BooleanField(default=False) + short_name = models.TextField(default="", blank=True) + timezone = models.TextField(default="America/New_York") + late_time = models.TimeField(null=True, blank=True) + + # Email and printing settings + printer_email = models.TextField(default="", blank=True) + mailchimp_api_key = models.TextField(default="", blank=True) + mailchimp_last_sync_person_changes = models.DateTimeField(null=True, blank=True) + mailchimp_updates_email = models.TextField(default="", blank=True) + + # JC settings + jc_reset_day = models.IntegerField(default=3) + show_last_modified_in_print = models.BooleanField(default=True) + show_history_in_print = models.BooleanField(default=True) + + # Feature flags show_custodia = models.BooleanField(default=False) - show_attendance = models.BooleanField(default=False) + show_attendance = models.BooleanField(default=True) show_electronic_signin = models.BooleanField(default=False) show_accounting = models.BooleanField(default=False) show_roles = models.BooleanField(default=False) enable_case_references = models.BooleanField(default=False) + + # Attendance settings attendance_enable_off_campus = models.BooleanField(default=False) attendance_show_reports = models.BooleanField(default=False) attendance_report_latest_departure_time = models.TimeField(null=True, blank=True) attendance_report_latest_departure_time_2 = models.TimeField(null=True, blank=True) + attendance_day_earliest_departure_time = models.TimeField(null=True, blank=True) attendance_report_late_fee = models.IntegerField(null=True, blank=True) attendance_report_late_fee_2 = models.IntegerField(null=True, blank=True) attendance_report_late_fee_interval = models.IntegerField(null=True, blank=True) @@ -37,19 +50,21 @@ class Meta: attendance_show_rate_in_checkin = models.BooleanField(default=False) attendance_enable_partial_days = models.BooleanField(default=False) attendance_day_latest_start_time = models.TimeField(null=True, blank=True) - attendance_day_earliest_departure_time = models.TimeField(null=True, blank=True) attendance_day_min_hours = models.FloatField(null=True, blank=True) attendance_partial_day_value = models.DecimalField( max_digits=10, decimal_places=2, null=True, blank=True ) - attendance_admin_pin = models.CharField(max_length=255, null=True, blank=True) - attendance_default_absence_code = models.CharField( - max_length=255, null=True, blank=True - ) + attendance_admin_pin = models.CharField(max_length=10, default="", blank=True) + attendance_default_absence_code = models.TextField(null=True, blank=True) attendance_default_absence_code_time = models.TimeField(null=True, blank=True) - roles_individual_term = models.TextField(null=True, blank=True) - roles_committee_term = models.TextField(null=True, blank=True) - roles_group_term = models.TextField(null=True, blank=True) + + # Roles settings + roles_individual_term = models.TextField(default="Clerk", null=True, blank=True) + roles_committee_term = models.TextField(default="Committee", null=True, blank=True) + roles_group_term = models.TextField(default="Group", null=True, blank=True) + + # Custodia settings + custodia_password = models.TextField(default="", blank=True) def __str__(self): return f"{self.id}-{self.name}" @@ -68,52 +83,131 @@ class Meta: class Tag(models.Model): class Meta: db_table = "tag" + constraints = [ + models.UniqueConstraint( + fields=["title", "organization"], name="unique_title_org" + ) + ] organization = models.ForeignKey("Organization", on_delete=models.PROTECT) title = models.TextField() - use_student_display = models.BooleanField() + use_student_display = models.BooleanField(default=False) - show_in_jc = models.BooleanField() - show_in_attendance = models.BooleanField() - show_in_menu = models.BooleanField() - show_in_account_balances = models.BooleanField() - show_in_roles = models.BooleanField() + show_in_jc = models.BooleanField(default=False) + show_in_attendance = models.BooleanField(default=False) + show_in_menu = models.BooleanField(default=True) + show_in_account_balances = models.BooleanField(default=False) + show_in_roles = models.BooleanField(default=True) class Person(models.Model): class Meta: db_table = "person" - first_name = models.CharField() - last_name = models.CharField() - display_name = models.CharField() + # Names and display + first_name = models.CharField(max_length=255, default="") + last_name = models.CharField(max_length=255, default="") + display_name = models.CharField(max_length=255, default="") + + # Family relationship family_person = models.ForeignKey( - "self", on_delete=models.PROTECT, null=True, blank=True + "self", + on_delete=models.PROTECT, + null=True, + blank=True, + db_column="family_person_id", ) + is_family = models.BooleanField(default=False) + + # Contact info + email = models.CharField(max_length=255, default="", blank=True) + address = models.CharField(max_length=255, default="", blank=True) + city = models.CharField(max_length=255, default="", blank=True) + state = models.CharField(max_length=255, default="", blank=True) + zip = models.CharField(max_length=255, default="", blank=True) + neighborhood = models.CharField(max_length=255, default="", blank=True) + + # Personal info + gender = models.TextField(default="Unknown") + dob = models.DateField(null=True, blank=True) + approximate_dob = models.DateField(null=True, blank=True) + grade = models.TextField(default="", blank=True) + notes = models.TextField(default="", blank=True) + + # School info + previous_school = models.CharField(max_length=255, default="") + school_district = models.CharField(max_length=255, default="") + + # System fields + id = models.AutoField(primary_key=True, db_column="person_id") + organization_id: int + organization = models.ForeignKey(Organization, on_delete=models.PROTECT) + tags = models.ManyToManyField(Tag, db_table="person_tag", blank=True) + created = models.DateTimeField(db_default=Now()) + pin = models.CharField(max_length=10, default="", blank=True) + + # Custodia fields + custodia_show_as_absent = models.DateField(null=True, blank=True) + custodia_start_date = models.DateField(null=True, blank=True) def get_name(self): return self.display_name or self.first_name - email = models.CharField(blank=True) + def __str__(self): + return f'{self.first_name} {self.last_name} "{self.display_name}" [Org {self.organization_id}]' - gender = models.CharField(blank=True) - address = models.CharField(blank=True) - city = models.CharField(blank=True) - state = models.CharField(blank=True) - zip = models.CharField(blank=True) - neighborhood = models.CharField(blank=True) - id = models.IntegerField(primary_key=True, db_column="person_id") - organization_id: int - organization = models.ForeignKey(Organization, on_delete=models.PROTECT) - tags = models.ManyToManyField(Tag, db_table="person_tag") +class PhoneNumber(models.Model): + class Meta: + db_table = "phone_numbers" - custodia_show_as_absent = models.DateField() - custodia_start_date = models.DateField() + person = models.ForeignKey(Person, on_delete=models.CASCADE) + comment = models.CharField(max_length=255, null=True, blank=True) + number = models.CharField(max_length=255, null=True, blank=True) - def __str__(self): - return f'{self.first_name} {self.last_name} "{self.display_name}" [Org {self.organization_id}]' + +class Donation(models.Model): + class Meta: + db_table = "donation" + + dollar_value = models.FloatField(null=True, blank=True) + is_cash = models.BooleanField() + description = models.TextField() + person = models.ForeignKey(Person, on_delete=models.CASCADE) + date = models.DateTimeField(db_default=Now()) + + thanked = models.BooleanField() + thanked_by_user = models.ForeignKey( + "User", + on_delete=models.PROTECT, + null=True, + blank=True, + related_name="donations_thanked", + db_column="thanked_by_user_id", + ) + thanked_time = models.DateTimeField(null=True, blank=True) + + indiegogo_reward_given = models.BooleanField() + indiegogo_reward_by_user = models.ForeignKey( + "User", + on_delete=models.PROTECT, + null=True, + blank=True, + related_name="donations_indiegogo_rewarded", + db_column="indiegogo_reward_by_user_id", + ) + indiegogo_reward_given_time = models.DateTimeField(null=True, blank=True) + + +class Email(models.Model): + class Meta: + db_table = "email" + + message = models.TextField(null=True, blank=True) + sent = models.BooleanField() + deleted = models.BooleanField() + organization = models.ForeignKey(Organization, on_delete=models.PROTECT) class Role(models.Model): @@ -122,6 +216,12 @@ class Meta: organization_id: int organization = models.ForeignKey(Organization, on_delete=models.PROTECT) + is_active = models.BooleanField(default=True) + type = models.IntegerField() + eligibility = models.IntegerField() + name = models.TextField() + notes = models.TextField() + description = models.TextField() class RoleRecord(models.Model): @@ -129,6 +229,8 @@ class Meta: db_table = "role_record" role = models.ForeignKey(Role, on_delete=models.PROTECT) + role_name = models.TextField() + date_created = models.DateTimeField() class RoleRecordMember(models.Model): @@ -138,7 +240,9 @@ class Meta: role_record = models.ForeignKey( RoleRecord, on_delete=models.PROTECT, db_column="record_id" ) - person = models.ForeignKey(Person, on_delete=models.PROTECT) + person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True, blank=True) + person_name = models.TextField(null=True, blank=True) + type = models.IntegerField() class AttendanceRule(models.Model): @@ -147,23 +251,38 @@ class Meta: organization_id: int organization = models.ForeignKey(Organization, on_delete=models.PROTECT) + category = models.TextField(null=True, blank=True) + person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True, blank=True) + start_date = models.DateField(null=True, blank=True) + end_date = models.DateField(null=True, blank=True) + monday = models.BooleanField() + tuesday = models.BooleanField() + wednesday = models.BooleanField() + thursday = models.BooleanField() + friday = models.BooleanField() + absence_code = models.CharField(max_length=64, null=True, blank=True) + min_hours = models.FloatField(null=True, blank=True) + latest_start_time = models.TimeField(null=True, blank=True) + earliest_departure_time = models.TimeField(null=True, blank=True) + exempt_from_fees = models.BooleanField() class Comment(models.Model): class Meta: db_table = "comments" - created = models.DateTimeField() - person = models.ForeignKey(Person, on_delete=models.PROTECT) - user = models.ForeignKey("User", on_delete=models.PROTECT) + message = models.TextField(null=True, blank=True) + created = models.DateTimeField(db_default=Now()) + person = models.ForeignKey(Person, on_delete=models.CASCADE) + user = models.ForeignKey("User", on_delete=models.PROTECT, db_column="user_id") class TaskList(models.Model): class Meta: db_table = "task_list" - title = models.CharField(max_length=255) - tag = models.ForeignKey(Tag, on_delete=models.PROTECT) + title = models.CharField(max_length=255, null=True, blank=True) + tag = models.ForeignKey(Tag, on_delete=models.PROTECT, null=True, blank=True) organization = models.ForeignKey(Organization, on_delete=models.PROTECT) @@ -171,15 +290,27 @@ class Task(models.Model): class Meta: db_table = "task" - task_list = models.ForeignKey(TaskList, on_delete=models.PROTECT) + title = models.CharField(max_length=255, null=True, blank=True) + task_list = models.ForeignKey( + TaskList, on_delete=models.PROTECT, null=True, blank=True + ) + sort_order = models.IntegerField(null=True, blank=True) + enabled = models.BooleanField(null=True, blank=True) class CompletedTask(models.Model): class Meta: db_table = "completed_task" + constraints = [ + models.UniqueConstraint( + fields=["task", "person"], name="unique_completed_task_1" + ) + ] - comment = models.ForeignKey(Comment, on_delete=models.PROTECT) - person = models.ForeignKey(Person, on_delete=models.PROTECT) + comment = models.ForeignKey( + Comment, on_delete=models.CASCADE, null=True, blank=True + ) + person = models.ForeignKey(Person, on_delete=models.CASCADE) task = models.ForeignKey(Task, on_delete=models.PROTECT) @@ -187,7 +318,9 @@ class NotificationRule(models.Model): class Meta: db_table = "notification_rule" - tag = models.ForeignKey(Tag, on_delete=models.PROTECT) + tag = models.ForeignKey(Tag, on_delete=models.PROTECT, null=True, blank=True) + the_type = models.IntegerField() + email = models.TextField() organization = models.ForeignKey(Organization, on_delete=models.PROTECT) @@ -196,6 +329,10 @@ class Meta: db_table = "mailchimp_sync" tag = models.ForeignKey(Tag, on_delete=models.PROTECT) + mailchimp_list_id = models.CharField(max_length=255) + sync_local_adds = models.BooleanField() + sync_local_removes = models.BooleanField() + last_sync = models.DateTimeField(null=True, blank=True) class AttendanceCode(models.Model): @@ -203,15 +340,20 @@ class Meta: db_table = "attendance_code" organization = models.ForeignKey(Organization, on_delete=models.PROTECT) + code = models.CharField(max_length=64) + description = models.TextField() + color = models.CharField(max_length=16) + counts_toward_attendance = models.BooleanField(default=False) + not_counted = models.BooleanField(default=False) class AttendanceDay(models.Model): class Meta: db_table = "attendance_day" constraints = [ - models.UniqueConstraint("person", "day", name="u_attendance_day") + models.UniqueConstraint(fields=["person", "day"], name="u_attendance_day") ] - indexes = [models.Index("day", name="attendance_day_day_idx")] + indexes = [models.Index(fields=["day"], name="attendance_day_day_idx")] person = models.ForeignKey(Person, on_delete=models.PROTECT) day = models.DateField() @@ -229,9 +371,11 @@ class AttendanceWeek(models.Model): class Meta: db_table = "attendance_week" constraints = [ - models.UniqueConstraint("person", "monday", name="u_attendance_week") + models.UniqueConstraint( + fields=["person", "monday"], name="u_attendance_week" + ) ] - indexes = [models.Index("monday", name="attendance_week_monday_idx")] + indexes = [models.Index(fields=["monday"], name="attendance_week_monday_idx")] person = models.ForeignKey(Person, on_delete=models.PROTECT) monday = models.DateField() @@ -243,9 +387,22 @@ class Meta: db_table = "person_tag_change" person = models.ForeignKey(Person, on_delete=models.PROTECT) - time = models.DateTimeField() - was_add = models.BooleanField() tag = models.ForeignKey(Tag, on_delete=models.PROTECT) + creator = models.ForeignKey( + "User", on_delete=models.PROTECT, db_column="creator_id" + ) + time = models.DateTimeField(db_default=Now()) + was_add = models.BooleanField() + + +class PersonChange(models.Model): + class Meta: + db_table = "person_change" + + person = models.ForeignKey(Person, on_delete=models.PROTECT) + old_email = models.CharField(max_length=255) + new_email = models.CharField(max_length=255) + time = models.DateTimeField(db_default=Now()) class ManualManager(models.Manager): @@ -310,6 +467,7 @@ class Meta: ) deleted = models.BooleanField(default=False) content = models.TextField() + is_breaking_res_plan = models.BooleanField(default=False) def number(self): return self.section.number() + "." + self.num @@ -329,25 +487,27 @@ class Meta: db_table = "manual_change" chapter = models.ForeignKey( - Chapter, on_delete=models.PROTECT, related_name="changes" + Chapter, on_delete=models.PROTECT, related_name="changes", null=True, blank=True ) section = models.ForeignKey( - Section, on_delete=models.PROTECT, related_name="changes" + Section, on_delete=models.PROTECT, related_name="changes", null=True, blank=True + ) + entry = models.ForeignKey( + Entry, on_delete=models.PROTECT, related_name="changes", null=True, blank=True ) - entry = models.ForeignKey(Entry, on_delete=models.PROTECT, related_name="changes") - date_entered = models.DateTimeField(auto_now_add=True) - effective_date = models.DateField(blank=True) - show_date_in_history = models.BooleanField(null=False, default=True) - user = models.ForeignKey("dst.User", on_delete=models.PROTECT) + date_entered = models.DateTimeField(db_default=Now()) + effective_date = models.DateField(null=True, blank=True) + show_date_in_history = models.BooleanField(default=True) + user = models.ForeignKey("User", on_delete=models.PROTECT, null=True, blank=True) was_deleted = models.BooleanField(default=False) was_created = models.BooleanField(default=False) old_content = models.TextField(null=True, blank=True) new_content = models.TextField(null=True, blank=True) - old_title = models.CharField() - new_title = models.CharField() - old_num = models.CharField() - new_num = models.CharField() + old_title = models.CharField(max_length=255, null=True, blank=True) + new_title = models.CharField(max_length=255, null=True, blank=True) + old_num = models.TextField(null=True, blank=True) + new_num = models.TextField(null=True, blank=True) def effective_date_with_fallback(self) -> date: return self.effective_date or self.date_entered.date() @@ -358,6 +518,15 @@ class Meta: db_table = "account" organization = models.ForeignKey(Organization, on_delete=models.PROTECT) + person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True, blank=True) + type = models.IntegerField() + initial_balance = models.DecimalField(max_digits=10, decimal_places=2) + name = models.TextField(default="") + monthly_credit = models.DecimalField( + max_digits=10, decimal_places=2, default=Decimal(0) + ) + date_last_monthly_credit = models.DateTimeField(null=True, blank=True) + is_active = models.BooleanField(default=True) class Transaction(models.Model): @@ -365,11 +534,46 @@ class Meta: db_table = "transactions" organization = models.ForeignKey(Organization, on_delete=models.PROTECT) + from_account = models.ForeignKey( + Account, + on_delete=models.PROTECT, + null=True, + blank=True, + related_name="transactions_from", + db_column="from_account_id", + ) + to_account = models.ForeignKey( + Account, + on_delete=models.PROTECT, + null=True, + blank=True, + related_name="transactions_to", + db_column="to_account_id", + ) + from_name = models.TextField() + to_name = models.TextField() + description = models.TextField() + type = models.IntegerField() + amount = models.DecimalField(max_digits=10, decimal_places=2) + date_created = models.DateTimeField() + created_by_user = models.ForeignKey( + "User", + on_delete=models.PROTECT, + null=True, + blank=True, + db_column="created_by_user_id", + ) + archived = models.BooleanField(default=False) class Meeting(models.Model): class Meta: db_table = "meeting" + constraints = [ + models.UniqueConstraint( + fields=["organization", "date"], name="unq_org_date" + ) + ] organization = models.ForeignKey(Organization, on_delete=models.PROTECT) date = models.DateField() @@ -378,8 +582,30 @@ class Meta: class Case(models.Model): class Meta: db_table = "case" + constraints = [ + models.UniqueConstraint( + fields=["case_number", "meeting"], name="u_case_number_meeting" + ) + ] + case_number = models.CharField(max_length=255, default="") + findings = models.TextField(default="") + date = models.DateField(null=True, blank=True) + location = models.CharField(max_length=255, default="") + time = models.CharField(max_length=255, default="") + date_closed = models.DateField(null=True, blank=True) meeting = models.ForeignKey(Meeting, on_delete=models.PROTECT) + meetings = models.ManyToManyField( + Meeting, through="CaseMeeting", related_name="cases_many" + ) + + +class CaseMeeting(models.Model): + class Meta: + db_table = "case_meeting" + + case = models.ForeignKey(Case, on_delete=models.CASCADE) + meeting = models.ForeignKey(Meeting, on_delete=models.CASCADE) class Charge(models.Model): @@ -387,20 +613,41 @@ class Meta: db_table = "charge" case = models.ForeignKey(Case, on_delete=models.PROTECT) - person = models.ForeignKey(Person, on_delete=models.PROTECT) + person = models.ForeignKey(Person, on_delete=models.PROTECT, null=True, blank=True) + rule = models.ForeignKey( + Entry, on_delete=models.PROTECT, null=True, blank=True, db_column="rule_id" + ) + plea = models.CharField(max_length=255, default="") + resolution_plan = models.TextField(default="") + referred_to_sm = models.BooleanField(default=False) + sm_decision = models.TextField(null=True, blank=True) + sm_decision_date = models.DateField(null=True, blank=True) + minor_referral_destination = models.CharField(max_length=255, default="") + severity = models.CharField(max_length=255, default="") + referenced_charge = models.ForeignKey( + "self", + on_delete=models.PROTECT, + null=True, + blank=True, + db_column="referenced_charge_id", + ) + rp_complete = models.BooleanField(default=False) + rp_complete_date = models.DateTimeField(null=True, blank=True) class ChargeReference(models.Model): class Meta: constraints = [ - models.UniqueConstraint("charge", "the_case", name="uk_charge_case") + models.UniqueConstraint( + fields=["referenced_charge", "referencing_case"], name="uk_charge_case" + ) ] db_table = "charge_reference" - charge = models.ForeignKey( + referenced_charge = models.ForeignKey( Charge, on_delete=models.PROTECT, db_column="referenced_charge" ) - the_case = models.ForeignKey( + referencing_case = models.ForeignKey( Case, on_delete=models.PROTECT, db_column="referencing_case" ) @@ -409,7 +656,7 @@ class CaseReference(models.Model): class Meta: constraints = [ models.UniqueConstraint( - "referenced_case", "referencing_case", name="uk_case_case" + fields=["referenced_case", "referencing_case"], name="uk_case_case" ) ] db_table = "case_reference" @@ -429,37 +676,40 @@ class PersonAtMeeting(models.Model): class Meta: db_table = "person_at_meeting" + meeting = models.ForeignKey( + Meeting, on_delete=models.PROTECT, null=True, blank=True + ) person = models.ForeignKey(Person, on_delete=models.PROTECT) + role = models.IntegerField(null=True, blank=True) class PersonAtCase(models.Model): class Meta: db_table = "person_at_case" + case = models.ForeignKey(Case, on_delete=models.PROTECT, null=True, blank=True) person = models.ForeignKey(Person, on_delete=models.PROTECT) - - -class PersonChange(models.Model): - class Meta: - db_table = "person_change" - - person = models.ForeignKey(Person, on_delete=models.PROTECT) + role = models.IntegerField(default=0) CHECKIN_USERNAME = "Check-in app user" class User(AbstractUser): - password = models.TextField(db_column="hashed_password") - class Meta: db_table = 'public"."users' + constraints = [ + models.UniqueConstraint(fields=["email"], name="users_unique_email_1") + ] + password = models.TextField(db_column="hashed_password") is_active = models.BooleanField( default=True, db_column="active", ) - organization = models.ForeignKey(Organization, on_delete=models.PROTECT) + organization = models.ForeignKey( + Organization, on_delete=models.PROTECT, null=True, blank=True + ) name = models.TextField() email = models.TextField() # override this so that emails aren't validated email_validated = models.BooleanField(default=False) @@ -525,6 +775,11 @@ class Meta: class LinkedAccount(models.Model): class Meta: db_table = 'public"."linked_account' + constraints = [ + models.UniqueConstraint( + fields=["provider_key", "provider_user_id"], name="u_linked_account" + ) + ] user = models.ForeignKey( User, on_delete=models.CASCADE, related_name="linked_accounts" @@ -537,5 +792,5 @@ class AllowedIp(models.Model): class Meta: db_table = "allowed_ips" - ip = models.TextField() + ip = models.TextField(primary_key=True) organization = models.ForeignKey(Organization, on_delete=models.PROTECT) diff --git a/django/dst/org_config.py b/django/dst/org_config.py index 66616b02..ecbf7030 100644 --- a/django/dst/org_config.py +++ b/django/dst/org_config.py @@ -7,6 +7,8 @@ def get_org_config(org: Organization) -> "OrgConfig": + init_org_configs() + return ALL_ORG_CONFIGS[org.name] @@ -435,22 +437,34 @@ def __init__(self): self.use_year_in_case_number = True -# Initialize all the configurations -# They will be automatically registered in ALL_ORG_CONFIGS -ThreeRiversVillageSchool() -PhillyFreeSchool() -Fairhaven() -TheCircleSchool() -MakariosLearningCommunity() -TheOpenSchool() -TheOpenSchoolVirtual() -Houston() -Sandbox() -Clearview() -Wicklow() -Tallgrass() -MiamiSudburySchool() -SligoSudburySchool() -LearningProjectIbiza() -Wilmington() -SouthJersey() +ORG_CONFIGS_LOADED = False + + +def init_org_configs(): + global ORG_CONFIGS_LOADED + if ORG_CONFIGS_LOADED: + return + + ORG_CONFIGS_LOADED = True + + # Initialize all the configurations. + # They will be automatically registered in ALL_ORG_CONFIGS. + # Don't do this at module load time because + # then this file won't load before the Organization table is created. + ThreeRiversVillageSchool() + PhillyFreeSchool() + Fairhaven() + TheCircleSchool() + MakariosLearningCommunity() + TheOpenSchool() + TheOpenSchoolVirtual() + Houston() + Sandbox() + Clearview() + Wicklow() + Tallgrass() + MiamiSudburySchool() + SligoSudburySchool() + LearningProjectIbiza() + Wilmington() + SouthJersey() diff --git a/django/test_initial_migrate.sh b/django/test_initial_migrate.sh new file mode 100755 index 00000000..9202bf99 --- /dev/null +++ b/django/test_initial_migrate.sh @@ -0,0 +1,32 @@ +set -ex + +psql << 'EOF' +\set ON_ERROR_STOP 1 +DROP DATABASE IF EXISTS school_crm; +CREATE DATABASE school_crm; +--- DROP ROLE IF EXISTS custodia; +EOF + + +######## +## Test coming from existing database + +# pg_restore -d school_crm -U postgres -O -e ~/Downloads/backup_2025_11_12/db.dump +# # Fake apply dst/0001_initial and custodia/0003_swipe_person_swipe_day_empty_out_unique +# # Don't use ./manage.py migrate because it gets confused. +# psql school_crm << 'EOF' +# \set ON_ERROR_STOP 1 +# INSERT INTO django_migrations(app, name, applied) VALUES +# ('dst', '0001_initial', clock_timestamp()), +# ('custodia', '0003_swipe_person_swipe_day_empty_out_unique', clock_timestamp()); +# EOF +# ./manage.py migrate +# pg_dump -O --schema-only school_crm > orig_sql.sql + + +######## +## Test starting from clean database + +./manage.py migrate +pg_dump -O --schema-only school_crm > django_migrate.sql +uv run manage.py setup_initial_data diff --git a/encapsulate_fields.py b/encapsulate_fields.py deleted file mode 100644 index c0dba05c..00000000 --- a/encapsulate_fields.py +++ /dev/null @@ -1,180 +0,0 @@ -import os -import re -import sys - - -def to_camel_case(snake_name: str): - result = [] - last_was_underscore = False - for c in snake_name: - if c == "_": - last_was_underscore = True - elif last_was_underscore: - last_was_underscore = False - result.append(c.upper()) - else: - result.append(c) - return "".join(result) - - -def generate_migration(table_name: str, replacements: dict[str, str]): - ev_path = "conf/evolutions/default" - file_count = len(os.listdir(ev_path)) - - ups = [] - downs = [] - - for old_name, new_name in replacements.items(): - if old_name == new_name: - continue - ups.append(f"alter table {table_name} rename column {old_name} to {new_name};") - downs.append( - f"alter table {table_name} rename column {new_name} to {old_name};" - ) - - with open(f"{ev_path}/{file_count + 1}.sql", "w") as f: - f.write("# --- !Ups \n\n") - f.write("\n".join(ups)) - f.write("\n\n# --- !Downs \n\n") - f.write("\n".join(downs)) - - -def encapsulate_fields(files: dict[str, str], path_to_model): - assert path_to_model.endswith(".java") - content = files[path_to_model] - if "@Entity" not in content: - print("Skipping", path_to_model, "because there is no @Entity") - return - - replacements = {} - types = {} - - out_lines = [] - for line in content.splitlines(): - match = re.match(r"(\t| )public ([a-zA-Z_.<>]+) (\w+)( ?= ?.*)?;", line) - # if 'public' in line: - # print(line) - if not match: - if line.strip() == "@Entity" and "@Getter" not in content: - out_lines.append("""\ -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter""") - out_lines.append(line) - continue - - old_var_name = match.group(3) - new_var_name = to_camel_case(old_var_name) - replacements[old_var_name] = new_var_name - types[old_var_name] = match.group(2) - - out_lines.append( - f' private {match.group(2)} {new_var_name}{match.group(4) or ""};' - ) - - if not replacements: - print("No changes to be made based on", path_to_model) - - files[path_to_model] = "\n".join(out_lines) - # generate_migration(get_table_name_from_path(path_to_model), replacements) - - for path, content in files.items(): - new_content = content - for old_var_name, new_var_name in replacements.items(): - if old_var_name in {"id", "name"}: - continue - - if old_var_name not in content: - continue - - capital_name = new_var_name[0].upper() + new_var_name[1:] - getter = "get" + capital_name - # if 'boolean' == types[old_var_name]: - # if new_var_name.startswith('is') and new_var_name[2].isupper(): - # getter = new_var_name - # else: - # getter = 'is' + capital_name - setter = "set" + capital_name - - if "modelsLibrary" not in path and ( - path.endswith(".java") or path.endswith(".scala.html") - ): - new_lines = [] - for line in new_content.splitlines(): - ignores = [ - ".fetch(", - ".eq(", - ".ne(", - "parse(", - "SELECT", - "@Where", - "import", - "filename=", - ".lt(", - ".ge(", - ".orderBy(", - ] - if not any(x in line for x in ignores): - # .foo_bar = value; --> .setFooBar(value); - line = re.sub( - rf"\.{old_var_name} ?=[^=](.*);", rf".{setter}(\1);", line - ) - # .foo_bar --> .getFooBar(); - line = re.sub(rf"\.{old_var_name}\b", f".{getter}()", line) - new_lines.append(line) - new_content = "\n".join(new_lines) + "\n" - - if old_var_name != new_var_name: - # "foo_bar" --> "fooBar" - new_content = re.sub(rf"\b{old_var_name}\b", new_var_name, new_content) - - files[path] = new_content - - -def get_table_name_from_path(path_to_model): - return os.path.basename(path_to_model).split(".")[0].lower() - - -def load_files_one_path(result, path): - for root, unused_dirs, files in os.walk(path): - for filename in files: - if filename not in {"app-compiled.js"} and ( - filename in {"routes"} - or os.path.splitext(filename)[1] in {".java", ".html", ".js", ".conf"} - ): - path = os.path.join(root, filename) - with open(path) as f: - result[path] = f.read() - - -def load_files() -> dict[str, str]: - result = {} - load_files_one_path(result, "app") - load_files_one_path(result, "conf") - load_files_one_path(result, "modelsLibrary/app") - return result - - -def write_files(files): - for path, content in files.items(): - old_content = None - with open(path) as f: - old_content = f.read() - - if content.strip() != old_content.strip(): - with open(path, "w") as f: - f.write(content) - - -def main(): - files = load_files() - for arg in sys.argv[1:]: - encapsulate_fields(files, arg) - - write_files(files) - - -if __name__ == "__main__": - main()