diff --git a/.github/workflows/cleanup-cron-workflow-runs.yaml b/.github/workflows/cleanup-cron-workflow-runs.yaml new file mode 100644 index 000000000..a98d4b0b9 --- /dev/null +++ b/.github/workflows/cleanup-cron-workflow-runs.yaml @@ -0,0 +1,19 @@ +name: Scheduled cleanup old workflow runs +on: + schedule: + - cron: '0 0 * * 0' +# At 00:00 on Sunday. + +jobs: + del_runs: + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Delete workflow runs + uses: Mattraks/delete-workflow-runs@v2.0.4 + with: + token: ${{ github.token }} + repository: ${{ github.repository }} + retain_days: 15 + keep_minimum_runs: 10 \ No newline at end of file diff --git a/.github/workflows/cleanup-workflow-runs.yaml b/.github/workflows/cleanup-workflow-runs.yaml new file mode 100644 index 000000000..13987355e --- /dev/null +++ b/.github/workflows/cleanup-workflow-runs.yaml @@ -0,0 +1,25 @@ +name: Cleanup old workflow runs +on: + workflow_dispatch: + inputs: + days: + description: 'Number of days.' + required: true + default: 15 + minimum_runs: + description: 'The minimum runs to keep for each workflow.' + required: true + default: 10 +jobs: + del_runs: + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Delete workflow runs + uses: Mattraks/delete-workflow-runs@v2.0.4 + with: + token: ${{ github.token }} + repository: ${{ github.repository }} + retain_days: ${{ github.event.inputs.days }} + keep_minimum_runs: ${{ github.event.inputs.minimum_runs }} diff --git a/.github/workflows/dev-release.yaml b/.github/workflows/dev-release.yaml new file mode 100644 index 000000000..db5890c3a --- /dev/null +++ b/.github/workflows/dev-release.yaml @@ -0,0 +1,129 @@ +## For each release, the value of name, branches, RELEASE_NAME and PR_NUMBER need to be adjusted accordingly +## For each release, update lib/config.js: version and releaseBranch + +name: TFRS Dev release-2.8.0 + +on: + push: + branches: [ release-2.8.0 ] + paths: + - frontend/** + - backend/** + workflow_dispatch: + workflow_call: + +env: + ## The pull request number of the Tracking pull request to merge the release branch to main + ## Also remember to update the version in .pipeline/lib/config.js + PR_NUMBER: 2384 + RELEASE_NAME: release-2.8.0 + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + + unit-test: + + name: Run Backend Unit Tests + runs-on: ubuntu-latest + timeout-minutes: 60 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Run coverage report for django tests + uses: kuanfandevops/django-test-action@itvr-django-test + continue-on-error: true + with: + settings-dir-path: "backend/api" + requirements-file: "backend/requirements.txt" + managepy-dir: backend + + lint: + + name: Linting + runs-on: ubuntu-latest + timeout-minutes: 60 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Frontend Linting + continue-on-error: true + run: | + cd frontend + pwd + npm install + npm run lint + + - name: Backend linting + uses: github/super-linter/slim@v4 + continue-on-error: true + env: + DEFAULT_BRANCH: ${{ env.RELEASE_NAME }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + FILTER_REGEX_INCLUDE: .*backend/.*.py + VALIDATE_PYTHON_PYLINT: true + LOG_LEVEL: WARN + + build: + + name: Build TFRS on Openshift + runs-on: ubuntu-latest + timeout-minutes: 60 + + steps: + + ## it will checkout to /home/runner/work/itvr/itvr + - name: Check out repository + uses: actions/checkout@v3 + + ## Log in to Openshift with a token of service account + - name: Log in to Openshift + ##uses: redhat-actions/oc-login@v1 + uses: smlgbl/oc-login@main + with: + openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} + openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} + insecure_skip_tls_verify: true + namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools + + ## Run build on Openshift + - name: Run build + run: | + cd .pipeline + npm install + npm run build -- --pr=${{ env.PR_NUMBER }} --env=build + + deploy-on-dev: + + name: Deploy TFRS on Dev + runs-on: ubuntu-latest + timeout-minutes: 240 + needs: build + + steps: + + ## it will checkout to /home/runner/work/itvr/itvr + - name: Check out repository + uses: actions/checkout@v3 + + - name: Log in to Openshift + ##uses: redhat-actions/oc-login@v1 + uses: smlgbl/oc-login@main + with: + openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} + openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} + insecure_skip_tls_verify: true + namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools + + - name: Run deploy + run: | + cd .pipeline + npm install + npm run deploy -- --pr=${{ env.PR_NUMBER }} --env=dev + diff --git a/.github/workflows/tfrs-release.yaml b/.github/workflows/tfrs-release.yaml index 4c950622f..aab1ad97d 100644 --- a/.github/workflows/tfrs-release.yaml +++ b/.github/workflows/tfrs-release.yaml @@ -1,22 +1,17 @@ ## For each release, the value of name, branches, RELEASE_NAME and PR_NUMBER need to be adjusted accordingly ## For each release, update lib/config.js: version and releaseBranch -name: TFRS release-2.7.0 +name: TFRS release-2.8.0 on: - push: - branches: [ release-2.7.0 ] - paths: - - frontend/** - - backend/** workflow_dispatch: workflow_call: env: ## The pull request number of the Tracking pull request to merge the release branch to main ## Also remember to update the version in .pipeline/lib/config.js - PR_NUMBER: 2320 - RELEASE_NAME: release-2.7.0 + PR_NUMBER: 2384 + RELEASE_NAME: release-2.8.0 concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -99,40 +94,12 @@ jobs: npm install npm run build -- --pr=${{ env.PR_NUMBER }} --env=build - deploy-on-dev: - - name: Deploy TFRS on Dev - runs-on: ubuntu-latest - timeout-minutes: 240 - needs: build - - steps: - - ## it will checkout to /home/runner/work/itvr/itvr - - name: Check out repository - uses: actions/checkout@v3 - - - name: Log in to Openshift - ##uses: redhat-actions/oc-login@v1 - uses: smlgbl/oc-login@main - with: - openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} - openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} - insecure_skip_tls_verify: true - namespace: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-tools - - - name: Run deploy - run: | - cd .pipeline - npm install - npm run deploy -- --pr=${{ env.PR_NUMBER }} --env=dev - deploy-on-test: name: Deploy TFRS on Test runs-on: ubuntu-latest timeout-minutes: 240 - needs: deploy-on-dev + needs: build steps: diff --git a/.pipeline/lib/config.js b/.pipeline/lib/config.js index a065520d1..b650ac4e9 100644 --- a/.pipeline/lib/config.js +++ b/.pipeline/lib/config.js @@ -1,7 +1,7 @@ 'use strict'; const options= require('@bcgov/pipeline-cli').Util.parseArguments() const changeId = options.pr //aka pull-request -const version = '2.7.0' +const version = '2.8.0' const name = 'tfrs' const ocpName = 'apps.silver.devops' @@ -13,7 +13,7 @@ options.git.repository='tfrs' const phases = { build: { namespace:'0ab226-tools' , name: `${name}`, phase: 'build' , changeId:changeId, suffix: `-build-${changeId}` , instance: `${name}-build-${changeId}` , version:`${version}-${changeId}`, tag:`build-${version}-${changeId}`, - releaseBranch: 'release-2.7.0' + releaseBranch: 'release-2.8.0' }, dev: {namespace:'0ab226-dev' , name: `${name}`, phase: 'dev' , changeId:changeId, suffix: `-dev` , instance: `${name}-dev` , version:`${version}`, tag:`dev-${version}`, dbServiceName: 'tfrs-spilo', diff --git a/backend/api/migrations/0001_initial.py b/backend/api/migrations/0001_initial.py deleted file mode 100644 index 5559cf81a..000000000 --- a/backend/api/migrations/0001_initial.py +++ /dev/null @@ -1,431 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-01-09 21:25 -from __future__ import unicode_literals - -import api.validators -from django.conf import settings -import django.contrib.auth.models -import django.contrib.auth.validators -import django.core.validators -from django.db import migrations, models -import django.db.models.deletion -import django.utils.timezone - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('auth', '0008_alter_user_username_max_length'), - ] - - operations = [ - migrations.CreateModel( - name='User', - fields=[ - ('id', models.AutoField(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=30, verbose_name='first name')), - ('last_name', models.CharField(blank=True, max_length=30, 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')), - ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), - ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('password', models.CharField(blank=True, max_length=128, null=True)), - ('email', models.EmailField(blank=True, max_length=254, null=True)), - ('title', models.CharField(blank=True, max_length=100, null=True)), - ('phone', models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')])), - ('cell_phone', models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')])), - ('effective_date', models.DateField(auto_now_add=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('authorization_id', models.CharField(blank=True, max_length=500, null=True)), - ('authorization_guid', models.UUIDField(default=None, null=True, unique=True)), - ('authorization_directory', models.CharField(blank=True, max_length=100, null=True)), - ('authorization_email', models.EmailField(blank=True, max_length=254, null=True)), - ('display_name', models.CharField(blank=True, max_length=500, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_user_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), - ], - options={ - 'db_table': 'user', - }, - managers=[ - ('objects', django.contrib.auth.models.UserManager()), - ], - ), - migrations.CreateModel( - name='CreditTrade', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('number_of_credits', models.IntegerField(validators=[api.validators.CreditTradeNumberOfCreditsValidator])), - ('fair_market_value_per_credit', models.DecimalField(blank=True, decimal_places=2, default=None, max_digits=999, null=True)), - ('trade_effective_date', models.DateField(blank=True, null=True)), - ('note', models.CharField(blank=True, max_length=4000, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittrade_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'credit_trade', - }, - ), - migrations.CreateModel( - name='CreditTradeHistory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('credit_trade_update_time', models.DateTimeField()), - ('number_of_credits', models.IntegerField()), - ('fair_market_value_per_credit', models.DecimalField(blank=True, decimal_places=2, default=None, max_digits=999, null=True)), - ('trade_effective_date', models.DateField(blank=True, null=True)), - ('note', models.CharField(blank=True, max_length=4000, null=True)), - ('is_internal_history_record', models.BooleanField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradehistory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('credit_trade', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_histories', to='api.CreditTrade')), - ], - options={ - 'db_table': 'credit_trade_history', - 'ordering': ['-create_timestamp'], - }, - ), - migrations.CreateModel( - name='CreditTradeStatus', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('status', models.CharField(blank=True, max_length=25, null=True)), - ('description', models.CharField(blank=True, max_length=4000, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('display_order', models.IntegerField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradestatus_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradestatus_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'credit_trade_status', - }, - ), - migrations.CreateModel( - name='CreditTradeType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('the_type', models.CharField(blank=True, max_length=25, null=True)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('display_order', models.IntegerField()), - ('is_gov_only_type', models.BooleanField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradetype_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradetype_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'credit_trade_type', - }, - ), - migrations.CreateModel( - name='CreditTradeZeroReason', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('reason', models.CharField(max_length=25)), - ('description', models.CharField(max_length=1000)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('display_order', models.IntegerField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradezeroreason_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradezeroreason_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'credit_trade_zero_reason', - }, - ), - migrations.CreateModel( - name='Organization', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('name', models.CharField(max_length=500)), - ('created_date', models.DateField()), - ], - options={ - 'db_table': 'organization', - }, - ), - migrations.CreateModel( - name='OrganizationActionsType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('the_type', models.CharField(max_length=25)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('display_order', models.IntegerField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationactionstype_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationactionstype_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'organization_actions_type', - }, - ), - migrations.CreateModel( - name='OrganizationAttachment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('file_name', models.CharField(blank=True, max_length=250, null=True)), - ('file_location', models.CharField(blank=True, max_length=2000, null=True)), - ('description', models.CharField(blank=True, max_length=4000, null=True)), - ('compliance_year', models.CharField(blank=True, max_length=25, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationattachment_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='api.Organization')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationattachment_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'organization_attachment', - }, - ), - migrations.CreateModel( - name='OrganizationBalance', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('validated_credits', models.BigIntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationbalance_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('credit_trade', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='balances', to='api.CreditTrade')), - ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='balances', to='api.Organization')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationbalance_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'organization_balance', - }, - ), - migrations.CreateModel( - name='OrganizationHistory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('history_text', models.CharField(max_length=1000)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationhistory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='history', to='api.Organization')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationhistory_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'organization_history', - }, - ), - migrations.CreateModel( - name='OrganizationStatus', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('status', models.CharField(max_length=25)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('display_order', models.IntegerField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationstatus_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationstatus_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'organization_status', - }, - ), - migrations.CreateModel( - name='OrganizationType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('type', models.CharField(max_length=25)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('display_order', models.IntegerField(blank=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationtype_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationtype_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'organization_type', - }, - ), - migrations.CreateModel( - name='Permission', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('code', models.CharField(max_length=100)), - ('name', models.CharField(max_length=100)), - ('description', models.CharField(max_length=1000)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_permission_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_permission_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'permission', - }, - ), - migrations.CreateModel( - name='Role', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('name', models.CharField(max_length=200)), - ('description', models.CharField(max_length=1000)), - ('is_government_role', models.BooleanField(default=False)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_role_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_role_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'role', - }, - ), - migrations.CreateModel( - name='RolePermission', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_rolepermission_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('permission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='role_permissions', to='api.Permission')), - ('role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='role_permissions', to='api.Role')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_rolepermission_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'role_permission', - }, - ), - migrations.CreateModel( - name='UserRole', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_userrole_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('role', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_roles', to='api.Role')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_userrole_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_roles', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'user_role', - }, - ), - migrations.AddField( - model_name='organization', - name='actions_type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='organizations', to='api.OrganizationActionsType'), - ), - migrations.AddField( - model_name='organization', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organization_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='organization', - name='status', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='organizations', to='api.OrganizationStatus'), - ), - migrations.AddField( - model_name='organization', - name='type', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='organizations', to='api.OrganizationType'), - ), - migrations.AddField( - model_name='organization', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organization_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='credittradehistory', - name='respondent', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_histories', to='api.Organization'), - ), - migrations.AddField( - model_name='credittradehistory', - name='status', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_histories', to='api.CreditTradeStatus'), - ), - migrations.AddField( - model_name='credittradehistory', - name='type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_histories', to='api.CreditTradeType'), - ), - migrations.AddField( - model_name='credittradehistory', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradehistory_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='credittradehistory', - name='user', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_histories', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='credittradehistory', - name='zero_reason', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_histories', to='api.CreditTradeZeroReason'), - ), - migrations.AddField( - model_name='credittrade', - name='initiator', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='initiator_credit_trades', to='api.Organization'), - ), - migrations.AddField( - model_name='credittrade', - name='respondent', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='respondent_credit_trades', to='api.Organization'), - ), - migrations.AddField( - model_name='credittrade', - name='status', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trades', to='api.CreditTradeStatus'), - ), - migrations.AddField( - model_name='credittrade', - name='type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trades', to='api.CreditTradeType'), - ), - migrations.AddField( - model_name='credittrade', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittrade_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='credittrade', - name='zero_reason', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trades', to='api.CreditTradeZeroReason'), - ), - migrations.AddField( - model_name='user', - name='organization', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='users', to='api.Organization'), - ), - migrations.AddField( - model_name='user', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_user_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='user', - name='user_permissions', - field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions'), - ), - ] diff --git a/backend/api/migrations/0001_squashed_0207_alter_notificationsubscription_notification_type.py b/backend/api/migrations/0001_squashed_0207_alter_notificationsubscription_notification_type.py index d29fd28fb..82f38580c 100644 --- a/backend/api/migrations/0001_squashed_0207_alter_notificationsubscription_notification_type.py +++ b/backend/api/migrations/0001_squashed_0207_alter_notificationsubscription_notification_type.py @@ -91,8 +91,6 @@ def drop_table_0024(apps, schema_editor): class Migration(migrations.Migration): - replaces = [('api', '0001_initial'), ('api', '0002_remove_organization_created_date'), ('api', '0003_auto_20180208_2119'), ('api', '0004_auto_20180209_2207'), ('api', '0005_auto_20180424_1445'), ('api', '0006_auto_20180424_1527'), ('api', '0007_credittradehistory_compliance_period'), ('api', '0008_auto_20180507_1734'), ('api', '0009_signingauthorityassertion_signingauthorityconfirmation'), ('api', '0010_auto_20180529_2003'), ('api', '0011_auto_20180613_1848'), ('api', '0012_credittradecomment'), ('api', '0013_auto_20180619_2053'), ('api', '0014_credittradecomment'), ('api', '0015_auto_20180625_1543'), ('api', '0016_rename_comment'), ('api', '0017_auto_20180628_2024'), ('api', '0018_auto_20180703_1718'), ('api', '0019_organizationaddress'), ('api', '0020_credittradecomment_trade_history_at_creation'), ('api', '0021_audit_triggers'), ('api', '0022_audit_tables'), ('api', '0023_core_data_load'), ('api', '0024_ops_data_tables'), ('api', '0025_historical_data_entry_permissions'), ('api', '0026_notificationchannel_notificationmessage_notificationsubscription'), ('api', '0027_auto_20180827_1414'), ('api', '0028_notificationmessage_is_archived'), ('api', '0029_government_of_bc_rename'), ('api', '0030_auto_20180919_2145'), ('api', '0031_role_display_order'), ('api', '0032_role_rename'), ('api', '0033_update_admin_permissions'), ('api', '0034_update_guest_permissions'), ('api', '0035_add_assign_role_permissions'), ('api', '0036_update_credit_statuses'), ('api', '0037_add_deputy_director_role'), ('api', '0038_credittradehistory_user_role'), ('api', '0039_usercreationrequest'), ('api', '0040_auto_20181024_2106'), ('api', '0039_update_fs_admin_permissions'), ('api', '0041_merge_20181031_2228'), ('api', '0042_update_credit_trader_role_description'), ('api', '0043_edit_user_permission_clean_up'), ('api', '0044_auto_20181122_2212'), ('api', '0045_documents'), ('api', '0046_document_data_load'), ('api', '0047_auto_20181205_1716'), ('api', '0048_auto_20181213_2313'), ('api', '0049_auto_20181217_1824'), ('api', '0050_documentfileattachment_filename'), ('api', '0051_auto_20181218_1654'), ('api', '0052_document_data_update'), ('api', '0053_auto_20181220_1644'), ('api', '0054_organization_descriptions_update'), ('api', '0055_role_permission_descriptions'), ('api', '0056_auto_20190103_2227'), ('api', '0057_auto_20190103_2247'), ('api', '0058_auto_20190103_2258'), ('api', '0059_comment_permissions'), ('api', '0060_documentcomment'), ('api', '0061_auto_20190110_2139'), ('api', '0062_auto_20190115_1640'), ('api', '0063_documents_permission_update'), ('api', '0064_new_document_statuses'), ('api', '0065_auto_20190114_2347'), ('api', '0066_documentfileattachment_is_removed'), ('api', '0067_permissions_remove_view_compliance_periods'), ('api', '0068_rename_fuel_supply_records'), ('api', '0069_remove_documenthistory_user_role'), ('api', '0070_rename_credit_retirement'), ('api', '0071_rename_document_upload'), ('api', '0072_notificationmessage_related_document'), ('api', '0073_auto_20190128_2014'), ('api', '0074_add_document_statuses'), ('api', '0075_remove_document_rescinded_status'), ('api', '0076_add_document_status_archived'), ('api', '0077_auto_20190211_1930'), ('api', '0078_auto_20190211_2127'), ('api', '0079_auto_20190219_1859'), ('api', '0080_remove_credittrade_note'), ('api', '0081_auto_20190220_0014'), ('api', '0082_document_link_permissions'), ('api', '0083_fuelcode'), ('api', '0084_fuelcodestatus'), ('api', '0085_add_fuel_code_statuses'), ('api', '0086_fuelcode_status'), ('api', '0087_add_fuel_code_permissions'), ('api', '0088_auto_20190228_1911'), ('api', '0089_auto_20190228_2106'), ('api', '0090_fuel_code_status_set_effective_dates'), ('api', '0091_rename_fsdoc_role'), ('api', '0092_auto_20190305_0417'), ('api', '0093_initial_transport_modes_and_approved_fuels'), ('api', '0094_auto_20190305_2356'), ('api', '0095_auto_20190301_1659'), ('api', '0096_add_trgm_extension'), ('api', '0097_add_autocomplete_indices'), ('api', '0098_rename_fuel_status_submitted'), ('api', '0099_add_approved_fuel'), ('api', '0100_auto_20190329_1942'), ('api', '0101_auto_20190329_2115'), ('api', '0102_auto_20190401_2109'), ('api', '0103_auto_20190402_2318'), ('api', '0104_auto_20190403_1616'), ('api', '0105_add_credit_calculation_permissions'), ('api', '0106_add_fuel_classes'), ('api', '0107_auto_20190404_1942'), ('api', '0108_auto_20190408_2311'), ('api', '0109_auto_20190409_2101'), ('api', '0110_add_credit_calculation_fuel_types'), ('api', '0111_update_credit_calculation_fuel_types'), ('api', '0112_auto_20190411_1530'), ('api', '0113_auto_20190411_1551'), ('api', '0114_add_categories'), ('api', '0115_auto_20190411_1615'), ('api', '0116_add_categories_to_approved_fuel'), ('api', '0117_add_unit_of_measures'), ('api', '0118_approvedfuel_description'), ('api', '0119_add_approved_fuel_descriptions'), ('api', '0120_approvedfuelclass'), ('api', '0121_add_fuel_class_relationships'), ('api', '0122_auto_20190425_1514'), ('api', '0123_auto_20190424_1639'), ('api', '0124_update_partially_renewable_fuels'), ('api', '0125_lowercase_renewable_fuel'), ('api', '0126_auto_20190502_2024'), ('api', '0127_add_petroleum_carbon_intensity_categories'), ('api', '0128_clean_filenames'), ('api', '0129_expecteduse'), ('api', '0130_auto_20190513_2144'), ('api', '0131_autosavedformdata_last_access'), ('api', '0132_auto_20190522_1753'), ('api', '0133_add_compliance_report_types_and_statuses'), ('api', '0134_add_compliance_reporting_roles'), ('api', '0135_auto_20190528_0110'), ('api', '0136_auto_20190528_0212'), ('api', '0137_notionaltransfertype'), ('api', '0138_auto_20190530_1823'), ('api', '0139_auto_20190604_1750'), ('api', '0140_fix_renewable_categories'), ('api', '0141_auto_20190606_2119'), ('api', '0142_auto_20190606_2119'), ('api', '0143_move_determination_types'), ('api', '0144_update_approved_fuel_xref'), ('api', '0145_auto_20190606_2202'), ('api', '0146_remove_provisionoftheact_determination_type'), ('api', '0147_auto_20190606_2242'), ('api', '0148_auto_20190607_1452'), ('api', '0149_auto_20190612_0150'), ('api', '0150_auto_20190619_1733'), ('api', '0151_rename_table_sequences'), ('api', '0152_edit_organization_address_permission'), ('api', '0153_remove_organizationaddress_primary'), ('api', '0154_add_address_effective_dates'), ('api', '0155_schedule_d'), ('api', '0156_auto_20190716_0523'), ('api', '0157_credittradecomment_is_deleted'), ('api', '0158_auto_20190716_2018'), ('api', '0159_schedulesummary_credits_offset'), ('api', '0160_auto_20190717_1830'), ('api', '0161_auto_20190718_1421'), ('api', '0162_auto_20190718_0625'), ('api', '0163_transactiontype'), ('api', '0164_auto_20190729_1810'), ('api', '0165_compliance_reporting_manager_role'), ('api', '0166_add_sign_compliance_report_permission'), ('api', '0167_compliancereporthistory'), ('api', '0168_signingauthorityconfirmation_title'), ('api', '0169_add_view_compliance_report_permission'), ('api', '0170_auto_20190819_0126'), ('api', '0171_add_idir_compliance_report_permissions'), ('api', '0172_add_compliance_report_new_statuses'), ('api', '0173_auto_20190819_1941'), ('api', '0174_auto_20190819_1942'), ('api', '0175_auto_20190819_1942'), ('api', '0176_auto_20190823_0131'), ('api', '0177_auto_20190821_1837'), ('api', '0178_documentfileattachment_scan_resubmit_ttl'), ('api', '0179_db_column_adjustments_for_compliance_reporting'), ('api', '0180_add_director_compliance_report_permissions'), ('api', '0181_auto_20190829_2036'), ('api', '0182_compliancereport_credit_transaction'), ('api', '0183_add_gov_analyst_view_compliance_report_permission'), ('api', '0184_add_request_supplemental_report_status'), ('api', '0185_compliancereport_supplements'), ('api', '0186_compliancereport_nickname'), ('api', '0187_auto_20190923_1556'), ('api', '0188_update_roles_permissions'), ('api', '0189_auto_20190930_2245'), ('api', '0190_compliancereport_supplemental_note'), ('api', '0191_role_default_role'), ('api', '0192_update_guest_role'), ('api', '0193_auto_20191017_1601'), ('api', '0194_auto_20191112_2114'), ('api', '0195_audit_additional_tables'), ('api', '0196_auto_20191121_1607'), ('api', '0197_update_guest_permissions'), ('api', '0198_update_compliance_report_permissions'), ('api', '0199_auto_20210421_1925'), ('api', '0200_auto_20221102_2220'), ('api', '0201_user_keycloak_user_id'), ('api', '0202_create_user_login_history'), ('api', '0203_auto_20230312_0823'), ('api', '0204_auto_20230321_0204'), ('api', '0205_auto_20230321_0206'), ('api', '0206_schedulesummary_credits_offset_c')] - initial = True dependencies = [ diff --git a/backend/api/migrations/0002_data_migration.py b/backend/api/migrations/0002_data_migration.py index 1bffb3d66..c4643730e 100644 --- a/backend/api/migrations/0002_data_migration.py +++ b/backend/api/migrations/0002_data_migration.py @@ -4917,8 +4917,6 @@ def remove_permissions_0198(apps, schema_editor): class Migration(migrations.Migration): - replaces = [('api', '0207_alter_notificationsubscription_notification_type')] - dependencies = [ ('api', '0001_squashed_0207_alter_notificationsubscription_notification_type'), ] diff --git a/backend/api/migrations/0002_remove_organization_created_date.py b/backend/api/migrations/0002_remove_organization_created_date.py deleted file mode 100644 index 9cf041a6f..000000000 --- a/backend/api/migrations/0002_remove_organization_created_date.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-01-10 22:07 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.RemoveField( - model_name='organization', - name='created_date', - ), - ] diff --git a/backend/api/migrations/0003_auto_20180208_2119.py b/backend/api/migrations/0003_auto_20180208_2119.py deleted file mode 100644 index ade0a0c40..000000000 --- a/backend/api/migrations/0003_auto_20180208_2119.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-02-08 21:19 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0002_remove_organization_created_date'), - ] - - operations = [ - migrations.AlterField( - model_name='credittradestatus', - name='status', - field=models.CharField(blank=True, max_length=25, null=True, unique=True), - ), - migrations.AlterField( - model_name='credittradetype', - name='the_type', - field=models.CharField(blank=True, max_length=25, null=True, unique=True), - ), - migrations.AlterField( - model_name='organizationactionstype', - name='the_type', - field=models.CharField(max_length=25, unique=True), - ), - migrations.AlterField( - model_name='organizationstatus', - name='status', - field=models.CharField(max_length=25, unique=True), - ), - migrations.AlterField( - model_name='organizationtype', - name='type', - field=models.CharField(max_length=25, unique=True), - ), - migrations.AlterField( - model_name='permission', - name='code', - field=models.CharField(max_length=100, unique=True), - ), - ] diff --git a/backend/api/migrations/0004_auto_20180209_2207.py b/backend/api/migrations/0004_auto_20180209_2207.py deleted file mode 100644 index 9a8be87b7..000000000 --- a/backend/api/migrations/0004_auto_20180209_2207.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-02-09 22:07 -from __future__ import unicode_literals - -from decimal import Decimal -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0003_auto_20180208_2119'), - ] - - operations = [ - migrations.AlterField( - model_name='credittrade', - name='fair_market_value_per_credit', - field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=999, null=True), - ), - ] diff --git a/backend/api/migrations/0005_auto_20180424_1445.py b/backend/api/migrations/0005_auto_20180424_1445.py deleted file mode 100644 index f09d646d4..000000000 --- a/backend/api/migrations/0005_auto_20180424_1445.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-04-24 14:45 -from __future__ import unicode_literals - -import django.contrib.auth.validators -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0004_auto_20180209_2207'), - ] - - operations = [ - migrations.AlterField( - model_name='user', - name='username', - field=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.ASCIIUsernameValidator()], verbose_name='username'), - ), - ] diff --git a/backend/api/migrations/0006_auto_20180424_1527.py b/backend/api/migrations/0006_auto_20180424_1527.py deleted file mode 100644 index e0a5294c9..000000000 --- a/backend/api/migrations/0006_auto_20180424_1527.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-04-24 15:27 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0005_auto_20180424_1445'), - ] - - operations = [ - migrations.CreateModel( - name='CompliancePeriod', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_complianceperiod_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_complianceperiod_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'compliance_period', - }, - ), - migrations.AddField( - model_name='credittrade', - name='compliance_period', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trades', to='api.CompliancePeriod'), - ), - ] diff --git a/backend/api/migrations/0007_credittradehistory_compliance_period.py b/backend/api/migrations/0007_credittradehistory_compliance_period.py deleted file mode 100644 index 6ae0d289f..000000000 --- a/backend/api/migrations/0007_credittradehistory_compliance_period.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-04-24 18:49 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0006_auto_20180424_1527'), - ] - - operations = [ - migrations.AddField( - model_name='credittradehistory', - name='compliance_period', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_histories', to='api.CompliancePeriod'), - ), - ] diff --git a/backend/api/migrations/0008_auto_20180507_1734.py b/backend/api/migrations/0008_auto_20180507_1734.py deleted file mode 100644 index fed968dea..000000000 --- a/backend/api/migrations/0008_auto_20180507_1734.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-05-07 17:34 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0007_credittradehistory_compliance_period'), - ] - - operations = [ - migrations.AlterModelOptions( - name='credittrade', - options={'permissions': (('credit_trade_approve', 'Can approve credit transfers'),)}, - ), - ] diff --git a/backend/api/migrations/0009_signingauthorityassertion_signingauthorityconfirmation.py b/backend/api/migrations/0009_signingauthorityassertion_signingauthorityconfirmation.py deleted file mode 100644 index 8280a9a11..000000000 --- a/backend/api/migrations/0009_signingauthorityassertion_signingauthorityconfirmation.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-05-14 15:38 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0008_auto_20180507_1734'), - ] - - operations = [ - migrations.CreateModel( - name='SigningAuthorityAssertion', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('description', models.CharField(blank=True, max_length=4000, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('display_order', models.IntegerField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_signingauthorityassertion_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_signingauthorityassertion_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'signing_authority_assertion', - }, - ), - migrations.CreateModel( - name='SigningAuthorityConfirmation', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('has_accepted', models.BooleanField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_signingauthorityconfirmation_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('credit_trade', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='confirmations', to='api.CreditTrade')), - ('signing_authority_assertion', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='confirmations', to='api.SigningAuthorityAssertion')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_signingauthorityconfirmation_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'signing_authority_confirmation', - }, - ), - ] diff --git a/backend/api/migrations/0010_auto_20180529_2003.py b/backend/api/migrations/0010_auto_20180529_2003.py deleted file mode 100644 index 23e4c60e6..000000000 --- a/backend/api/migrations/0010_auto_20180529_2003.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-05-29 20:03 -from __future__ import unicode_literals - -import api.validators -from decimal import Decimal -import django.contrib.auth.validators -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0009_signingauthorityassertion_signingauthorityconfirmation'), - ] - - operations = [ - migrations.AlterField( - model_name='credittrade', - name='fair_market_value_per_credit', - field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=999, null=True, validators=[api.validators.CreditTradeFairMarketValueValidator]), - ), - migrations.AlterField( - model_name='user', - name='username', - field=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'), - ), - ] diff --git a/backend/api/migrations/0011_auto_20180613_1848.py b/backend/api/migrations/0011_auto_20180613_1848.py deleted file mode 100644 index 2fa5c30b0..000000000 --- a/backend/api/migrations/0011_auto_20180613_1848.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-13 18:48 -from __future__ import unicode_literals - -import django.core.validators -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0010_auto_20180529_2003'), - ] - - operations = [ - migrations.AlterModelOptions( - name='credittrade', - options={}, - ), - migrations.AlterField( - model_name='user', - name='cell_phone', - field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message=b"Phone number must be entered in theformat: '+999999999'. Up to 15 digitsallowed.", regex=b'^\\+?1?\\d{9,15}$')]), - ), - migrations.AlterField( - model_name='user', - name='phone', - field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message=b"Phone number must be entered in theformat: '+999999999'. Up to 15 digitsallowed.", regex=b'^\\+?1?\\d{9,15}$')]), - ), - ] diff --git a/backend/api/migrations/0012_credittradecomment.py b/backend/api/migrations/0012_credittradecomment.py deleted file mode 100644 index 8f8e3bcf7..000000000 --- a/backend/api/migrations/0012_credittradecomment.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-15 21:09 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0011_auto_20180613_1848'), - ] - - operations = [ - migrations.CreateModel( - name='CreditTradeComment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('comment', models.CharField(blank=True, max_length=4000, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradecomment_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('credit_trade', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_comments', to='api.CreditTrade')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_credittradecomment_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ('privileged_access', models.BooleanField(default=True)), - ], - options={ - 'ordering': ['create_timestamp'], - 'db_table': 'credit_trade_comment', - }, - ), - ] diff --git a/backend/api/migrations/0013_auto_20180619_2053.py b/backend/api/migrations/0013_auto_20180619_2053.py deleted file mode 100644 index 646c7ef00..000000000 --- a/backend/api/migrations/0013_auto_20180619_2053.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-19 20:53 -from __future__ import unicode_literals - -import django.core.validators -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0012_credittradecomment'), - ] - - operations = [ - migrations.AddField( - model_name='credittrade', - name='rescinded', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='credittradehistory', - name='rescinded', - field=models.BooleanField(default=False), - ), - migrations.AlterField( - model_name='user', - name='cell_phone', - field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')]), - ), - migrations.AlterField( - model_name='user', - name='phone', - field=models.CharField(blank=True, max_length=17, null=True, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')]), - ), - ] diff --git a/backend/api/migrations/0014_credittradecomment.py b/backend/api/migrations/0014_credittradecomment.py deleted file mode 100644 index 63cf3a301..000000000 --- a/backend/api/migrations/0014_credittradecomment.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-19 17:57 -from __future__ import unicode_literals - -import django.core.validators -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0013_auto_20180619_2053'), - ] - - operations = [ - migrations.AlterField( - model_name='credittradecomment', - name='credit_trade', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_comments', to='api.CreditTrade'), - ) - ] diff --git a/backend/api/migrations/0015_auto_20180625_1543.py b/backend/api/migrations/0015_auto_20180625_1543.py deleted file mode 100644 index 029bc850b..000000000 --- a/backend/api/migrations/0015_auto_20180625_1543.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-25 15:43 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0014_credittradecomment'), - ] - - operations = [ - migrations.RenameField( - model_name='credittrade', - old_name='rescinded', - new_name='is_rescinded', - ), - migrations.RenameField( - model_name='credittradehistory', - old_name='rescinded', - new_name='is_rescinded', - ), - ] diff --git a/backend/api/migrations/0016_rename_comment.py b/backend/api/migrations/0016_rename_comment.py deleted file mode 100644 index 7090c52ba..000000000 --- a/backend/api/migrations/0016_rename_comment.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-22 17:21 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0015_auto_20180625_1543'), - ] - - operations = [ - migrations.AlterField( - model_name='credittradecomment', - name='comment', - field=models.CharField(blank=True, db_column='credit_trade_comment', max_length=4000, null=True), - ), - ] diff --git a/backend/api/migrations/0017_auto_20180628_2024.py b/backend/api/migrations/0017_auto_20180628_2024.py deleted file mode 100644 index f3d6dbb99..000000000 --- a/backend/api/migrations/0017_auto_20180628_2024.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-28 20:24 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0016_rename_comment'), - ] - - operations = [ - migrations.AlterModelManagers( - name='user', - managers=[ - ], - ), - migrations.AlterField( - model_name='role', - name='name', - field=models.CharField(max_length=200, unique=True), - ), - ] diff --git a/backend/api/migrations/0018_auto_20180703_1718.py b/backend/api/migrations/0018_auto_20180703_1718.py deleted file mode 100644 index 26f21cbad..000000000 --- a/backend/api/migrations/0018_auto_20180703_1718.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-07-03 17:18 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0017_auto_20180628_2024'), - ] - - operations = [ - migrations.AlterField( - model_name='credittradecomment', - name='privileged_access', - field=models.BooleanField(db_column='is_privileged_access', default=True), - ), - ] diff --git a/backend/api/migrations/0019_organizationaddress.py b/backend/api/migrations/0019_organizationaddress.py deleted file mode 100644 index 346afbd34..000000000 --- a/backend/api/migrations/0019_organizationaddress.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-07-17 21:48 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0018_auto_20180703_1718'), - ] - - operations = [ - migrations.CreateModel( - name='OrganizationAddress', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('primary', models.BooleanField(default=False)), - ('address_line_1', models.CharField(blank=True, max_length=500, null=True)), - ('address_line_2', models.CharField(blank=True, max_length=100, null=True)), - ('address_line_3', models.CharField(blank=True, max_length=100, null=True)), - ('city', models.CharField(blank=True, max_length=100, null=True)), - ('postal_code', models.CharField(blank=True, max_length=10, null=True)), - ('state', models.CharField(blank=True, max_length=50, null=True)), - ('county', models.CharField(blank=True, max_length=50, null=True)), - ('country', models.CharField(blank=True, max_length=100, null=True)), - ('other', models.CharField(blank=True, max_length=100, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationaddress_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='addresses', to='api.Organization')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_organizationaddress_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'organization_address', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0020_credittradecomment_trade_history_at_creation.py b/backend/api/migrations/0020_credittradecomment_trade_history_at_creation.py deleted file mode 100644 index f079bacd4..000000000 --- a/backend/api/migrations/0020_credittradecomment_trade_history_at_creation.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-07-19 16:57 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0019_organizationaddress'), - ] - - operations = [ - migrations.AddField( - model_name='credittradecomment', - name='trade_history_at_creation', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='credit_trade_comments', to='api.CreditTradeHistory'), - ), - ] diff --git a/backend/api/migrations/0021_audit_triggers.py b/backend/api/migrations/0021_audit_triggers.py deleted file mode 100644 index bb5cd7770..000000000 --- a/backend/api/migrations/0021_audit_triggers.py +++ /dev/null @@ -1,35 +0,0 @@ -from django.db import migrations - -FILENAME = 'api/migrations/create_audit_trigger.sql' - - -def create_trigger(apps, schema_editor): - - if schema_editor.connection.vendor != 'postgresql': - return - - with open(FILENAME, 'r') as file: - sql = file.read() - - with schema_editor.connection.cursor() as cursor: - cursor.execute(sql) - - -def drop_trigger(apps, schema_editor): - - if schema_editor.connection.vendor != 'postgresql': - return - - with schema_editor.connection.cursor() as cursor: - cursor.execute('drop schema tfrs_audit cascade;') - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0020_credittradecomment_trade_history_at_creation'), - ] - - operations = [ - migrations.RunPython(create_trigger, drop_trigger) - ] diff --git a/backend/api/migrations/0022_audit_tables.py b/backend/api/migrations/0022_audit_tables.py deleted file mode 100644 index c2eeb5966..000000000 --- a/backend/api/migrations/0022_audit_tables.py +++ /dev/null @@ -1,22 +0,0 @@ -from django.db import migrations - -from api.migrations.operations.trigger_operation import AuditTable - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0021_audit_triggers'), - ] - - _tables = ['credit_trade', - 'credit_trade_comment', - 'credit_trade_history', - 'organization', - 'organization_balance', - 'user_role', - 'user', - 'signing_authority_confirmation' - ] - - operations = [AuditTable(table) for table in _tables] diff --git a/backend/api/migrations/0023_core_data_load.py b/backend/api/migrations/0023_core_data_load.py deleted file mode 100644 index 82cb9e163..000000000 --- a/backend/api/migrations/0023_core_data_load.py +++ /dev/null @@ -1,345 +0,0 @@ -from datetime import datetime - -from django.db import migrations, IntegrityError -from django.db.migrations import RunPython - - -def create_initial_data(apps, schema_editor): - """Load initial data (previously stored in fixtures) - This is for core (essential) data only -- operational data should be inserted with scripts - - This script is designed to look for existing data and add any missing elements, without - disrupting existing data, or load a database from nothing (as for testing) - - It is idempotent and irreversible - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately versioned - # for this migration (so this shouldn't ever need to be maintained if fields change) - permission = apps.get_model("api", "Permission") - ct_status = apps.get_model("api", "CreditTradeStatus") - ct_type = apps.get_model("api", "CreditTradeType") - ct_zero_reason = apps.get_model("api", "CreditTradeZeroReason") - org_actions_type = apps.get_model("api", "OrganizationActionsType") - org_type = apps.get_model("api", "OrganizationType") - org_status = apps.get_model("api", "OrganizationStatus") - role = apps.get_model("api", "Role") - org = apps.get_model("api", "Organization") - org_balance = apps.get_model("api", "OrganizationBalance") - role_permission = apps.get_model("api", "RolePermission") - signing_authority_assertion = apps.get_model("api", "SigningAuthorityAssertion") - compliance_period = apps.get_model("api", "CompliancePeriod") - - permissions = [ - permission(code='LOGIN', name='LOGIN', - description='A minimum permission needed for an authenticated user to access the system.'), - permission(code='ADMIN', name='System Administrator', - description='Gives the user System Administration power in the system. Assignment of this permission should go to a very limited set of users an an as needed/backup basis.'), - permission(code='USER_MANAGEMENT', name='User Management', - description='Gives the user access to the User Management screens'), - permission(code='ROLES_AND_PERMISSIONS', name='Roles and Permissions', - description='Gives the user access to the Roles and Permissions screens'), - permission(code='ADD_FS_USER', name='Add Fuel Supplier User', description='Add Fuel Supplier User'), - permission(code='VIEW_APPROVED_CREDIT_TRANSFERS', name='View Approved Credit Transfers', - description='View Approved Credit Transfers'), - permission(code='VIEW_CREDIT_TRANSFERS', name='View Credit Transfers', description='View Credit Transfers'), - permission(code='VIEW_FUEL_SUPPLIERS', name='View Fuel Suppliers', description='View Fuel Suppliers'), - permission(code='EDIT_FUEL_SUPPLIERS', name='Edit Fuel Suppliers', description='Gives the user access to create and update Fuel Suppliers'), - permission(code='PROPOSE_CREDIT_TRANSFER', name='Propose Credit Transfer', - description='Propose Credit Transfer'), - permission(code='RESCIND_CREDIT_TRANSFER', name='Rescind Credit Transfer', - description='Rescind Credit Transfer'), - permission(code='REFUSE_CREDIT_TRANSFER', name='Refuse Credit Transfer', description='Refuse Credit Transfer'), - permission(code='SIGN_CREDIT_TRANSFER', name='Sign Credit Transfer', description='Sign Credit Transfer'), - permission(code='RECOMMEND_CREDIT_TRANSFER', name='Recommend Credit Transfer', - description='Recommend/Not Recommend Credit Transfer'), - permission(code='DECLINE_CREDIT_TRANSFER', name='Decline Transfer', description='Decline Transfer'), - permission(code='APPROVE_CREDIT_TRANSFER', name='Approve Transfer', description='Approve Transfer'), - permission(code='VIEW_PRIVILEGED_COMMENTS', name='View Privileged Comments', - description='Gives the user access to view privileged comments'), - permission(code='EDIT_PRIVILEGED_COMMENTS', name='Edit Privileged Comments', - description='Gives the user access to edit privileged comments'), - permission(code='VIEW_COMPLIANCE_PERIODS', name='View Compliance Periods', - description='Gives the user access to view compliance periods'), - permission(code='EDIT_COMPLIANCE_PERIODS', name='Edit Compliance Periods', - description='Gives the user access to edit compliance periods') - ] - - for new_permission in permissions: - if not permission.objects.using(db_alias).filter(code=new_permission.code).exists(): - permission.objects.using(db_alias).bulk_create([new_permission]) - else: - print('skipping existing permission {}'.format(new_permission.code)) - - ct_statuses = [ - ct_status(id=1, status='Draft', - description='The Credit Transfer has been created but is only visible to the initiating organization.', - display_order=1, effective_date='2017-01-01'), - ct_status(id=2, status='Submitted', - description='The Credit Transfer Proposal has been created and is visible to both the initiating and responding Fuel Suppliers, and is waiting on the response from the Respondent.', - display_order=2, effective_date='2017-01-01'), - ct_status(id=3, status='Accepted', - description='The Credit Transfer has been accepted by the Respondent and is waiting on approval by the Director.', - display_order=3, effective_date='2017-01-01'), - ct_status(id=4, status='Recommended', - description='The Credit Transfer has been has been reviewed by a Government Analyst and is Recommended for Approval by the Director.', - display_order=4, effective_date='2017-01-01'), - ct_status(id=5, status='Not Recommended', - description='The Credit Transfer has been has been reviewed by a Government Analyst and is Not Recommended for Approval by the Director.', - display_order=4, effective_date='2017-01-01'), - ct_status(id=6, status='Approved', - description='The Credit Transfer has been has been approved by the Director and will be Completed as soon as the Effective Date of the Credit Trade has been reached.', - display_order=5, effective_date='2017-01-01'), - ct_status(id=7, status='Completed', - description='The Credit Transfer has been Completed and the Credit Balance(s) of the Fuel Supplier(s) has been updated.', - display_order=6, effective_date='2017-01-01'), - ct_status(id=8, status='Cancelled', - description='The Credit Transfer has been cancelled by one of the participants in the Credit Trade. Shows up as Rescinded or Refused.', - display_order=7, effective_date='2017-01-01'), - ct_status(id=9, status='Declined', description='The Credit Transfer has been rejected by the Director.', - display_order=8, effective_date='2017-01-01'), - ct_status(id=10, status='Refused', description='The Credit Transfer has been refused by the Respondent.', - display_order=9, effective_date='2017-01-01') - ] - - for new_ct_status in ct_statuses: - if not ct_status.objects.using(db_alias).filter(id=new_ct_status.id).exists(): - ct_status.objects.using(db_alias).bulk_create([new_ct_status]) - else: - print('skipping existing credit trade status {}'.format(new_ct_status.status)) - - ct_types = [ - ct_type(id=1, the_type='Sell', - description='The selling of Low Carbon Fuel Credits by the Initiator of the Trade or Opportunity.', - display_order=1, effective_date='2017-01-01', expiration_date='2117-01-01', is_gov_only_type=False), - ct_type(id=2, the_type='Buy', - description='The buying of Low Carbon Fuel Credits by the Initiator of the Trade or Opportunity.', - display_order=2, effective_date='2017-01-01', expiration_date='2117-01-01', is_gov_only_type=False), - ct_type(id=3, the_type='Credit Validation', - description='An adjustment of the number of Fuel Credits owned by a Fuel Supplier initiated by the BC Government.', - display_order=3, effective_date='2017-01-01', expiration_date='2117-01-01', is_gov_only_type=True), - ct_type(id=4, the_type='Credit Retirement', - description='The retirement of Fuel Credits owned by a Fuel Supplier by the BC Government.', - display_order=4, effective_date='2017-01-01', expiration_date='2117-01-01', is_gov_only_type=True), - ct_type(id=5, the_type='Part 3 Award', - description='The awarding of Low Carbon Fuel Credits to a Fuel Supplier following the completion of a Part 3 Agreement milestone.', - display_order=5, effective_date='2017-01-01', expiration_date='2117-01-01', is_gov_only_type=True) - ] - - for new_ct_type in ct_types: - if not ct_type.objects.using(db_alias).filter(id=new_ct_type.id).exists(): - ct_type.objects.using(db_alias).bulk_create([new_ct_type]) - else: - print('skipping existing credit trade type {}'.format(new_ct_type.the_type)) - - ct_zero_reasons = [ - ct_zero_reason(id=1, reason='Internal', - description='The credits were transferred between units within a single organization at no cost.', - display_order=1, effective_date='2017-01-01', expiration_date='2117-01-01'), - ct_zero_reason(id=2, reason='Other', - description='The transaction was at zero cost for some other reason. Specify the details in the comment box below.', - display_order=2, effective_date='2017-01-01', expiration_date='2117-01-01'), - ] - - for new_ct_zero_reason in ct_zero_reasons: - if not ct_zero_reason.objects.using(db_alias).filter(id=new_ct_zero_reason.id).exists(): - ct_zero_reason.objects.using(db_alias).bulk_create([new_ct_zero_reason]) - else: - print('skipping existing credit trade zero reason {}'.format(new_ct_zero_reason.reason)) - - org_actions_types = [ - org_actions_type(id=1, the_type='Buy And Sell', - description='An Organization permitted to both Buy and Sell Low Carbon Credits.', - display_order=1, effective_date='2017-01-01', expiration_date=None), - org_actions_type(id=2, the_type='Sell Only', - description='An Organization permitted to only to Sell Low Carbon Credits.', display_order=2, - effective_date='2017-01-01', expiration_date=None), - org_actions_type(id=3, the_type='None', - description='An Organization not currently permitted to either Buy and Sell Low Carbon Credits.', - display_order=3, effective_date='2017-01-01', expiration_date=None) - ] - - for new_org_actions_type in org_actions_types: - if not org_actions_type.objects.using(db_alias).filter(id=new_org_actions_type.id).exists(): - org_actions_type.objects.using(db_alias).bulk_create([new_org_actions_type]) - else: - print('skipping existing organization actions type {}'.format(new_org_actions_type.the_type)) - - org_types = [ - org_type(id=1, type='Government', description='Government of British Columbia', display_order=1, - effective_date='2017-01-01', expiration_date='2117-01-01'), - org_type(id=2, type='Part3FuelSupplier', description='A Part 3 Fuel Supplier who can do credit transfers', - display_order=2, effective_date='2017-01-01', expiration_date='2117-01-01') - ] - - for new_org_type in org_types: - if not org_type.objects.using(db_alias).filter(id=new_org_type.id).exists(): - org_type.objects.using(db_alias).bulk_create([new_org_type]) - else: - print('skipping existing organization type {}'.format(new_org_type.type)) - - org_statuses = [ - org_status(id=1, status='Active', - description='The Fuel Supplier is an active participant in the Low Carbon Credits trading market.', - display_order=1, effective_date='2017-01-01', expiration_date=None), - org_status(id=2, status='Archived', - description='The Fuel Supplier has been archived and is no longer a participant in the Low Carbon Credits trading market.', - display_order=1, effective_date='2017-01-01', expiration_date=None) - ] - - for new_org_status in org_statuses: - if not org_status.objects.using(db_alias).filter(id=new_org_status.id).exists(): - org_status.objects.using(db_alias).bulk_create([new_org_status]) - else: - print('skipping existing organization status {}'.format(new_org_status.status)) - - roles = [ - role(name='Admin', description='A System Administrator in the application with User Management and Roles and Permissions access.', is_government_role=True), - role(name='FSManager', description='A Fuel Supplier user with authority to act on behalf of the Fuel Supplier on Credit Transfers.', is_government_role=False), - role(name='FSUser', description='A Fuel Supplier user with limited abilities to take actions.', is_government_role=False), - role(name='GovDirector', description='A government user with authorization to Approve Credit Transfers.', is_government_role=True), - role(name='GovUser', description='A regular government user in the system.', is_government_role=True) - ] - - for new_role in roles: - if not role.objects.using(db_alias).filter(name=new_role.name).exists(): - role.objects.using(db_alias).bulk_create([new_role]) - else: - print('skipping existing role {}'.format(new_role.name)) - - role_permissions = [ - role_permission(role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get(code='EDIT_COMPLIANCE_PERIODS')), - role_permission(role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get(code='EDIT_FUEL_SUPPLIERS')), - role_permission(role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get(code='LOGIN')), - role_permission(role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get(code='ROLES_AND_PERMISSIONS')), - role_permission(role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get(code='USER_MANAGEMENT')), - role_permission(role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get(code='VIEW_COMPLIANCE_PERIODS')), - role_permission(role=role.objects.using(db_alias).get(name='FSManager'), - permission=permission.objects.using(db_alias).get(code='PROPOSE_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='FSManager'), - permission=permission.objects.using(db_alias).get(code='LOGIN')), - role_permission(role=role.objects.using(db_alias).get(name='FSManager'), - permission=permission.objects.using(db_alias).get(code='REFUSE_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='FSManager'), - permission=permission.objects.using(db_alias).get(code='RESCIND_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='FSManager'), - permission=permission.objects.using(db_alias).get(code='SIGN_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='FSManager'), - permission=permission.objects.using(db_alias).get(code='VIEW_CREDIT_TRANSFERS')), - role_permission(role=role.objects.using(db_alias).get(name='FSUser'), - permission=permission.objects.using(db_alias).get(code='LOGIN')), - role_permission(role=role.objects.using(db_alias).get(name='FSUser'), - permission=permission.objects.using(db_alias).get(code='PROPOSE_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='FSUser'), - permission=permission.objects.using(db_alias).get(code='REFUSE_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='FSUser'), - permission=permission.objects.using(db_alias).get(code='RESCIND_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='FSUser'), - permission=permission.objects.using(db_alias).get(code='VIEW_CREDIT_TRANSFERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='APPROVE_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='LOGIN')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='DECLINE_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='EDIT_FUEL_SUPPLIERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='EDIT_PRIVILEGED_COMMENTS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='VIEW_APPROVED_CREDIT_TRANSFERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='VIEW_COMPLIANCE_PERIODS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='EDIT_COMPLIANCE_PERIODS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='VIEW_CREDIT_TRANSFERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='VIEW_FUEL_SUPPLIERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get(code='VIEW_PRIVILEGED_COMMENTS')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='LOGIN')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='PROPOSE_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='EDIT_FUEL_SUPPLIERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='EDIT_PRIVILEGED_COMMENTS')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='RECOMMEND_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='RESCIND_CREDIT_TRANSFER')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='VIEW_APPROVED_CREDIT_TRANSFERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='VIEW_COMPLIANCE_PERIODS')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='VIEW_CREDIT_TRANSFERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='VIEW_FUEL_SUPPLIERS')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='VIEW_PRIVILEGED_COMMENTS')) - ] - - for new_role_permission in role_permissions: - if not role_permission.objects.using(db_alias).filter(role=role.objects.using(db_alias).get(name=new_role_permission.role.name), - permission=permission.objects.using(db_alias).get(code=new_role_permission.permission.code)).exists(): - role_permission.objects.using(db_alias).bulk_create([new_role_permission]) - else: - print('skipping existing role<->permission {}:{}'.format(new_role_permission.role.name, - new_role_permission.permission.code)) - - if not org.objects.using(db_alias).filter(id=1).exists(): - org.objects.using(db_alias).create( - id=1, - type=org_type.objects.using(db_alias).get(type='Government'), - actions_type=org_actions_type.objects.using(db_alias).get(the_type='Buy And Sell'), - status=org_status.objects.using(db_alias).get(status='Active'), - name='Government Of British Columbia' - ) - - org_balance.objects.using(db_alias).create( - credit_trade=None, - effective_date='2017-04-01', - expiration_date=None, - organization_id=1, - validated_credits=1000000000000000 - ) - else: - print('skipped creating existing government organization') - - if not compliance_period.objects.using(db_alias).all(): - compliance_period.objects.using(db_alias).create( - display_order=1, - effective_date=datetime.today().strftime('%Y-%m-%d'), - expiration_date=None, - description="Auto-generated initial compliance period" - ) - - if not signing_authority_assertion.objects.using(db_alias).all(): - signing_authority_assertion.objects.using(db_alias).create( - display_order=1, - effective_date=datetime.today().strftime('%Y-%m-%d'), - expiration_date=None, - description="Auto-generated initial signing authority assertion" - ) - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0022_audit_tables'), - ] - - operations = [ - # This is a one-way trip - RunPython(create_initial_data, reverse_code=None) - ] diff --git a/backend/api/migrations/0024_ops_data_tables.py b/backend/api/migrations/0024_ops_data_tables.py deleted file mode 100644 index b26557565..000000000 --- a/backend/api/migrations/0024_ops_data_tables.py +++ /dev/null @@ -1,60 +0,0 @@ -from django.db import migrations - -from api.migrations.operations.trigger_operation import AuditTable - -def create_table(apps, schema_editor): - - ddl_postgresql = 'create table data_load_operations(id serial4 not null primary key, ' \ - 'script_name varchar(1024) not null, ' \ - 'is_reverting bool not null, ' \ - 'successful bool not null, ' \ - 'comment text, ' \ - 'source_code text, ' \ - 'run_at timestamp without time zone not null);' \ - 'comment on table data_load_operations is \'Maintain a record of calls to the load_ops_data management command\';' \ - 'comment on column data_load_operations.id is \'Primary Key\'; ' \ - 'comment on column data_load_operations.script_name is \'Script file name\'; ' \ - 'comment on column data_load_operations.is_reverting is \'True if this was a run to revert a script\'; ' \ - 'comment on column data_load_operations.successful is \'True if the run completed successfully\'; ' \ - 'comment on column data_load_operations.comment is \'Script comment\'; ' \ - 'comment on column data_load_operations.source_code is \'Python source code for the script\'; ' \ - 'comment on column data_load_operations.run_at is \'The time the script run was started\';' - - ddl_sqlite = 'create table data_load_operations(id integer not null primary key autoincrement, ' \ - 'script_name varchar(1024) not null, ' \ - 'is_reverting bool not null, ' \ - 'successful bool not null, ' \ - 'comment text, ' \ - 'source_code text, ' \ - 'run_at timestamp without time zone);' - - sql = {} - sql['sqlite'] = ddl_sqlite - sql['postgresql'] = ddl_postgresql - - if schema_editor.connection.vendor not in sql.keys(): - return - - with schema_editor.connection.cursor() as cursor: - cursor.execute(sql[schema_editor.connection.vendor]) - - -def drop_table(apps, schema_editor): - - if schema_editor.connection.vendor not in ['sqlite', 'postgresql']: - return - - with schema_editor.connection.cursor() as cursor: - cursor.execute('drop table data_load_operations;') - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0023_core_data_load'), - ] - - operations = [ - migrations.RunPython(create_table, drop_table), - AuditTable('data_load_operations') - ] diff --git a/backend/api/migrations/0025_historical_data_entry_permissions.py b/backend/api/migrations/0025_historical_data_entry_permissions.py deleted file mode 100644 index 4d38b9078..000000000 --- a/backend/api/migrations/0025_historical_data_entry_permissions.py +++ /dev/null @@ -1,69 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def create_permissions(apps, schema_editor): - """ - Adds the historical data entry permission and attach it to the - Government User and Government Director roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role = apps.get_model("api", "Role") - role_permission = apps.get_model("api", "RolePermission") - - permission.objects.using(db_alias).create( - code="USE_HISTORICAL_DATA_ENTRY", - name="Use Historical Data Entry", - description="Allows the user to use the functions of " - "Historical Data Entry" - ) - - role_permission.objects.using(db_alias).bulk_create([ - role_permission( - role=role.objects.using(db_alias).get(name='GovDirector'), - permission=permission.objects.using(db_alias).get( - code='USE_HISTORICAL_DATA_ENTRY') - ), - role_permission( - role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get( - code='USE_HISTORICAL_DATA_ENTRY') - ) - ]) - - -def delete_permissions(apps, schema_editor): - """ - Removes the historical data entry permission from the Government roles - and deletes the actual permission. - - This is for reversing the migration. - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role_permission = apps.get_model("api", "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code="USE_HISTORICAL_DATA_ENTRY", - role__name__in=["GovDirector", "GovUser"]).delete() - - permission.objects.using(db_alias).filter( - code="USE_HISTORICAL_DATA_ENTRY" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - - dependencies = [ - ('api', '0024_ops_data_tables'), - ] - - operations = [ - RunPython(create_permissions, delete_permissions) - ] diff --git a/backend/api/migrations/0026_notificationchannel_notificationmessage_notificationsubscription.py b/backend/api/migrations/0026_notificationchannel_notificationmessage_notificationsubscription.py deleted file mode 100644 index 77ab4142e..000000000 --- a/backend/api/migrations/0026_notificationchannel_notificationmessage_notificationsubscription.py +++ /dev/null @@ -1,118 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-08-23 20:30 -from __future__ import unicode_literals - -from django.db.migrations import RunPython - -from api.models.NotificationChannel import NotificationChannel -import api.notifications.notifications -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -def create_notification_channels(apps, schema_editor): - """ - Adds the IN-APP, SMS, and EMAIL communications channels, with default settings - """ - db_alias = schema_editor.connection.alias - - channel = apps.get_model("api", "NotificationChannel") - - channel.objects.using(db_alias).bulk_create([ - channel(channel=NotificationChannel.AvailableChannels.IN_APP.name, enabled=True, subscribe_by_default=True), - channel(channel=NotificationChannel.AvailableChannels.SMS.name, enabled=False, subscribe_by_default=False), - channel(channel=NotificationChannel.AvailableChannels.EMAIL.name, enabled=True, subscribe_by_default=False) - ]) - - -def delete_notification_channels(apps, schema_editor): - """ - Removes the historical data entry permission from the Government roles - and deletes the actual permission. - - This is for reversing the migration. - """ - db_alias = schema_editor.connection.alias - - channel = apps.get_model("api", "NotificationChannel") - - channel.objects.using(db_alias).filter( - channel__in=[NotificationChannel.AvailableChannels.IN_APP.name, - NotificationChannel.AvailableChannels.SMS.name, - NotificationChannel.AvailableChannels.EMAIL.name] - ).delete() - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0025_historical_data_entry_permissions'), - ] - - operations = [ - migrations.CreateModel( - name='NotificationChannel', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('channel', models.CharField(choices=[(NotificationChannel.AvailableChannels('In-Application'), 'In-Application'), (NotificationChannel.AvailableChannels('SMS'), 'SMS'), (NotificationChannel.AvailableChannels('Email'), 'Email')], max_length=64, unique=True)), - ('enabled', models.BooleanField()), - ('subscribe_by_default', models.BooleanField()), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notificationchannel_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notificationchannel_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'notification_channel', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='NotificationMessage', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('message', models.CharField(max_length=4000)), - ('is_read', models.BooleanField(default=False)), - ('is_warning', models.BooleanField(default=False)), - ('is_error', models.BooleanField(default=False)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notificationmessage_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('originating_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='notification_originating_user', to=settings.AUTH_USER_MODEL)), - ('related_credit_trade', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='api.CreditTrade')), - ('related_organization', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='api.Organization')), - ('related_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='notification_related_user', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notificationmessage_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'notification_message', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='NotificationSubscription', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('notification_type', models.CharField(choices=[(api.notifications.notification_types.NotificationType('Credit Transfer Proposal Created'), 'Credit Transfer Proposal Created'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 1/2'), 'Credit Transfer Proposal Signed 1/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 2/2'), 'Credit Transfer Proposal Signed 2/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Refused'), 'Credit Transfer Proposal Refused'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Accepted'), 'Credit Transfer Proposal Accepted'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Approval'), 'Credit Transfer Proposal Recommended For Approval'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Declination'), 'Credit Transfer Proposal Recommended For Declination'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Declined'), 'Credit Transfer Proposal Declined'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Approved'), 'Credit Transfer Proposal Approved'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Rescinded'), 'Credit Transfer Proposal Rescinded'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Comment Created Or Updated'), 'Credit Transfer Proposal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Internal Comment Created Or Updated'), 'Credit Transfer Proposal Internal Comment Created Or Updated')], max_length=128)), - ('enabled', models.BooleanField()), - ('channel', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.NotificationChannel')), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notificationsubscription_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notificationsubscription_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'notification_subscription', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AlterUniqueTogether( - name='notificationsubscription', - unique_together=set([('user', 'channel', 'notification_type')]), - ), - RunPython(create_notification_channels, delete_notification_channels) - ] diff --git a/backend/api/migrations/0027_auto_20180827_1414.py b/backend/api/migrations/0027_auto_20180827_1414.py deleted file mode 100644 index 9668d6141..000000000 --- a/backend/api/migrations/0027_auto_20180827_1414.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-08-27 21:14 -from __future__ import unicode_literals - -from api.models.NotificationChannel import NotificationChannel -import api.notifications.notification_types -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0026_notificationchannel_notificationmessage_notificationsubscription'), - ] - - operations = [ - migrations.AlterField( - model_name='notificationchannel', - name='channel', - field=models.CharField(choices=[(NotificationChannel.AvailableChannels('In-Application'), 'IN_APP'), (NotificationChannel.AvailableChannels('SMS'), 'SMS'), (NotificationChannel.AvailableChannels('Email'), 'EMAIL')], max_length=64, unique=True), - ), - migrations.AlterField( - model_name='notificationsubscription', - name='notification_type', - field=models.CharField(choices=[(api.notifications.notification_types.NotificationType('Credit Transfer Proposal Created'), 'Credit Transfer Proposal Created'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 1/2'), 'Credit Transfer Proposal Signed 1/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 2/2'), 'Credit Transfer Proposal Signed 2/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Refused'), 'Credit Transfer Proposal Refused'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Accepted'), 'Credit Transfer Proposal Accepted'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Approval'), 'Credit Transfer Proposal Recommended For Approval'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Declination'), 'Credit Transfer Proposal Recommended For Declination'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Declined'), 'Credit Transfer Proposal Declined'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Approved'), 'Credit Transfer Proposal Approved'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Rescinded'), 'Credit Transfer Proposal Rescinded'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Comment Created Or Updated'), 'Credit Transfer Proposal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Internal Comment Created Or Updated'), 'Credit Transfer Proposal Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Created'), 'PVR Created'), (api.notifications.notification_types.NotificationType('PVR Recommended For Approval'), 'PVR Recommended For Approval'), (api.notifications.notification_types.NotificationType('PVR Pulled Back'), 'PVR Pulled Back'), (api.notifications.notification_types.NotificationType('PVR Declined'), 'PVR Declined'), (api.notifications.notification_types.NotificationType('PVR Approved'), 'PVR Approved'), (api.notifications.notification_types.NotificationType('PVR Comment Created Or Updated'), 'PVR Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Internal Comment Created Or Updated'), 'PVR Internal Comment Created Or Updated')], max_length=128), - ), - ] diff --git a/backend/api/migrations/0028_notificationmessage_is_archived.py b/backend/api/migrations/0028_notificationmessage_is_archived.py deleted file mode 100644 index d038406e9..000000000 --- a/backend/api/migrations/0028_notificationmessage_is_archived.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-09-11 19:08 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0027_auto_20180827_1414'), - ] - - operations = [ - migrations.AddField( - model_name='notificationmessage', - name='is_archived', - field=models.BooleanField(default=False), - ), - ] diff --git a/backend/api/migrations/0029_government_of_bc_rename.py b/backend/api/migrations/0029_government_of_bc_rename.py deleted file mode 100644 index d8f3a84d6..000000000 --- a/backend/api/migrations/0029_government_of_bc_rename.py +++ /dev/null @@ -1,45 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_organization_name(apps, schema_editor): - """ - Renames Government Of British Columbia to - Government of British Columbia - (lowercase 'of') - """ - db_alias = schema_editor.connection.alias - - organization = apps.get_model("api", "Organization") - - organization.objects.using(db_alias).filter( - name="Government Of British Columbia" - ).update(name="Government of British Columbia") - - -def revert_organization_name(apps, schema_editor): - """ - Renames Government of British Columbia back to - Government Of British Columbia - (lowercase 'Of') - """ - db_alias = schema_editor.connection.alias - - organization = apps.get_model("api", "Organization") - - organization.objects.using(db_alias).filter( - name="Government of British Columbia" - ).update(name="Government Of British Columbia") - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0028_notificationmessage_is_archived'), - ] - - operations = [ - RunPython(update_organization_name, revert_organization_name) - ] diff --git a/backend/api/migrations/0030_auto_20180919_2145.py b/backend/api/migrations/0030_auto_20180919_2145.py deleted file mode 100644 index 40cb0e345..000000000 --- a/backend/api/migrations/0030_auto_20180919_2145.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-09-19 21:45 -from __future__ import unicode_literals - -import api.notifications.notification_types -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0029_government_of_bc_rename'), - ] - - operations = [ - migrations.AlterField( - model_name='notificationsubscription', - name='notification_type', - field=models.CharField(choices=[(api.notifications.notification_types.NotificationType('Credit Transfer Proposal Created'), 'Credit Transfer Proposal Created'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 1/2'), 'Credit Transfer Proposal Signed 1/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 2/2'), 'Credit Transfer Proposal Signed 2/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Refused'), 'Credit Transfer Proposal Refused'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Accepted'), 'Credit Transfer Proposal Accepted'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Approval'), 'Credit Transfer Proposal Recommended For Approval'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Declination'), 'Credit Transfer Proposal Recommended For Declination'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Declined'), 'Credit Transfer Proposal Declined'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Approved'), 'Credit Transfer Proposal Approved'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Rescinded'), 'Credit Transfer Proposal Rescinded'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Comment Created Or Updated'), 'Credit Transfer Proposal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Internal Comment Created Or Updated'), 'Credit Transfer Proposal Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Created'), 'PVR Created'), (api.notifications.notification_types.NotificationType('PVR Recommended For Approval'), 'PVR Recommended For Approval'), (api.notifications.notification_types.NotificationType('PVR Rescinded'), 'PVR Rescinded'), (api.notifications.notification_types.NotificationType('PVR Pulled Back'), 'PVR Pulled Back'), (api.notifications.notification_types.NotificationType('PVR Declined'), 'PVR Declined'), (api.notifications.notification_types.NotificationType('PVR Approved'), 'PVR Approved'), (api.notifications.notification_types.NotificationType('PVR Comment Created Or Updated'), 'PVR Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Internal Comment Created Or Updated'), 'PVR Internal Comment Created Or Updated')], max_length=128), - ), - ] diff --git a/backend/api/migrations/0031_role_display_order.py b/backend/api/migrations/0031_role_display_order.py deleted file mode 100644 index 2137e0f02..000000000 --- a/backend/api/migrations/0031_role_display_order.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-10-01 19:09 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0030_auto_20180919_2145'), - ] - - operations = [ - migrations.AddField( - model_name='role', - name='display_order', - field=models.IntegerField(default=1), - preserve_default=False, - ), - ] diff --git a/backend/api/migrations/0032_role_rename.py b/backend/api/migrations/0032_role_rename.py deleted file mode 100644 index d3962b8fb..000000000 --- a/backend/api/migrations/0032_role_rename.py +++ /dev/null @@ -1,151 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_roles_descriptions(apps, schema_editor): - """ - Renames the descriptions of the roles to something - more useful - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model("api", "Role") - - role.objects.using(db_alias).filter( - name="Admin" - ).update( - description="Administrator", - display_order=3 - ) - - role.objects.using(db_alias).filter( - name="GovUser" - ).update( - description="Government Analyst", - display_order=1 - ) - - role.objects.using(db_alias).filter( - name="GovDirector" - ).update( - description="Government Director", - display_order=2 - ) - - role.objects.using(db_alias).filter( - name="FSUser" - ).update( - description="Credit Trader", - display_order=4 - ) - - role.objects.using(db_alias).filter( - name="FSManager" - ).update( - description="Signing Authority", - display_order=5 - ) - - fs_admin = role.objects.using(db_alias).filter( - name="FSAdmin" - ) - - if fs_admin: - fs_admin.update( - description="Managing User", - display_order=6 - ) - else: - role.objects.using(db_alias).create( - name="FSAdmin", - description="Managing User", - is_government_role=False, - display_order=6 - ) - - guest = role.objects.using(db_alias).filter( - name="FSNoAccess" - ) - - if guest: - guest.update( - description="Guest", - display_order=7 - ) - else: - role.objects.using(db_alias).create( - name="FSNoAccess", - description="Guest", - is_government_role=False, - display_order=7 - ) - - -def revert_roles_descriptions(apps, schema_editor): - """ - Renames the descriptions back to their previous states - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model("api", "Role") - - role.objects.using(db_alias).filter( - name="Admin" - ).update( - description="A System Administrator in the application with User " - "Management and Roles and Permissions access." - ) - - role.objects.using(db_alias).filter( - name="GovUser" - ).update( - description="A regular government user in the system." - ) - - role.objects.using(db_alias).filter( - name="GovDirector" - ).update( - description="A government user with authorization to Approve Credit " - "Transfers." - ) - - role.objects.using(db_alias).filter( - name="FSUser" - ).update( - description="A Fuel Supplier user with limited abilities to take " - "actions." - ) - - role.objects.using(db_alias).filter( - name="FSManager" - ).update( - description="A Fuel Supplier user with authority to act on behalf of " - "the Fuel Supplier on Credit Transfers." - ) - - role.objects.using(db_alias).filter( - name="FSAdmin" - ).update( - description="A Fuel Supplier adminuser with authority to add and " - "remove organizational users." - ) - - role.objects.using(db_alias).filter( - name="FSNoAccess" - ).update( - description="A Fuel Supplier user defined in the system, but with no " - "access to system functionality." - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0031_role_display_order'), - ] - - operations = [ - RunPython(update_roles_descriptions, revert_roles_descriptions) - ] diff --git a/backend/api/migrations/0033_update_admin_permissions.py b/backend/api/migrations/0033_update_admin_permissions.py deleted file mode 100644 index ae0b76876..000000000 --- a/backend/api/migrations/0033_update_admin_permissions.py +++ /dev/null @@ -1,79 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_permissions(apps, schema_editor): - """ - Updates the permissions and removes the create/edit fuel suppliers - from Government Analyst and Director roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role = apps.get_model("api", "Role") - role_permission = apps.get_model("api", "RolePermission") - - permission.objects.using(db_alias).create( - code='EDIT_FUEL_SUPPLIER_USERS', - name="Edit Fuel Supplier Users' Information" - ) - - role_permission.objects.using(db_alias).bulk_create([ - role_permission( - role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get( - code='EDIT_FUEL_SUPPLIER_USERS') - ), - role_permission( - role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get( - code='VIEW_APPROVED_CREDIT_TRANSFERS') - ), - role_permission( - role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get( - code='VIEW_CREDIT_TRANSFERS') - ), - role_permission( - role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get( - code='VIEW_FUEL_SUPPLIERS') - ) - ]) - - -def revert_permissions(apps, schema_editor): - """ - Reverts the permission back to its previous state by assigning - back the permission back to Government Analyst and Director - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role_permission = apps.get_model("api", "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "EDIT_FUEL_SUPPLIER_USERS", - "VIEW_APPROVED_CREDIT_TRANSFERS", - "VIEW_CREDIT_TRANSFERS", - "VIEW_FUEL_SUPPLIERS" - ], - role__name="Admin").delete() - - permission.objects.using(db_alias).filter( - code="EDIT_FUEL_SUPPLIER_USERS" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0032_role_rename'), - ] - - operations = [ - RunPython(update_permissions, revert_permissions) - ] diff --git a/backend/api/migrations/0034_update_guest_permissions.py b/backend/api/migrations/0034_update_guest_permissions.py deleted file mode 100644 index 87b87342c..000000000 --- a/backend/api/migrations/0034_update_guest_permissions.py +++ /dev/null @@ -1,51 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_permissions(apps, schema_editor): - """ - Updates the permissions and removes the create/edit fuel suppliers - from Government Analyst and Director roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role = apps.get_model("api", "Role") - role_permission = apps.get_model("api", "RolePermission") - - role_permission.objects.using(db_alias).bulk_create([ - role_permission( - role=role.objects.using(db_alias).get(name='FSNoAccess'), - permission=permission.objects.using(db_alias).get( - code='VIEW_CREDIT_TRANSFERS') - ) - ]) - - -def revert_permissions(apps, schema_editor): - """ - Reverts the permission back to its previous state by assigning - back the permission back to Government Analyst and Director - """ - db_alias = schema_editor.connection.alias - - role_permission = apps.get_model("api", "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "VIEW_CREDIT_TRANSFERS" - ], - role__name="FSNoAccess").delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0033_update_admin_permissions'), - ] - - operations = [ - RunPython(update_permissions, revert_permissions) - ] diff --git a/backend/api/migrations/0035_add_assign_role_permissions.py b/backend/api/migrations/0035_add_assign_role_permissions.py deleted file mode 100644 index c7746de1b..000000000 --- a/backend/api/migrations/0035_add_assign_role_permissions.py +++ /dev/null @@ -1,74 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_permissions(apps, schema_editor): - """ - Updates the Admin permissions so it can assign roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role = apps.get_model("api", "Role") - role_permission = apps.get_model("api", "RolePermission") - - permission.objects.using(db_alias).create( - code="ASSIGN_GOVERNMENT_ROLES", - name="Assign Government Roles", - description="Allows the user to assign government roles to users" - ) - - permission.objects.using(db_alias).create( - code="ASSIGN_FS_ROLES", - name="Assign Fuel Supplier Roles", - description="Allows the user to assign fuel supplier roles to users" - ) - - role_permission.objects.using(db_alias).bulk_create([ - role_permission( - role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get( - code='ASSIGN_GOVERNMENT_ROLES') - ), - role_permission( - role=role.objects.using(db_alias).get(name='Admin'), - permission=permission.objects.using(db_alias).get( - code='ASSIGN_FS_ROLES') - ), - role_permission( - role=role.objects.using(db_alias).get(name='FSAdmin'), - permission=permission.objects.using(db_alias).get( - code='ASSIGN_FS_ROLES') - ) - ]) - - -def revert_permissions(apps, schema_editor): - """ - Removes the permissions for assigning roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role_permission = apps.get_model("api", "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code__in=["ASSIGN_FS_ROLES", "ASSIGN_GOVERNMENT_ROLES"] - ).delete() - - permission.objects.using(db_alias).filter( - code__in=["ASSIGN_FS_ROLES", "ASSIGN_GOVERNMENT_ROLES"] - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0034_update_guest_permissions'), - ] - - operations = [ - RunPython(update_permissions, revert_permissions) - ] diff --git a/backend/api/migrations/0036_update_credit_statuses.py b/backend/api/migrations/0036_update_credit_statuses.py deleted file mode 100644 index 833002d8a..000000000 --- a/backend/api/migrations/0036_update_credit_statuses.py +++ /dev/null @@ -1,68 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_status(apps, schema_editor): - """ - Updates the permissions and removes the create/edit fuel suppliers - from Government Analyst and Director roles - """ - db_alias = schema_editor.connection.alias - - status = apps.get_model("api", "CreditTradeStatus") - - status.objects.using(db_alias).filter( - status="Approved" - ).update( - status="Recorded", - description="The Credit Transfer has been has been recorded by " - "the Government Analyst" - ) - - status.objects.using(db_alias).filter( - status="Completed" - ).update( - status="Approved", - description="The Credit Transfer has been Approved and the Credit " - "Balance(s) of the Fuel Supplier(s) has been updated." - ) - - -def revert_status(apps, schema_editor): - """ - Reverts the permission back to its previous state by assigning - back the permission back to Government Analyst and Director - """ - db_alias = schema_editor.connection.alias - - status = apps.get_model("api", "CreditTradeStatus") - - status.objects.using(db_alias).filter( - status="Approved" - ).update( - status="Completed", - description="The Credit Transfer has been Completed and the Credit " - "Balance(s) of the Fuel Supplier(s) has been updated." - ) - - status.objects.using(db_alias).filter( - status="Recorded" - ).update( - status="Approved", - description="The Credit Transfer has been has been approved by the " - "Director and will be Completed as soon as the Effective " - "Date of the Credit Trade has been reached." - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0035_add_assign_role_permissions'), - ] - - operations = [ - RunPython(update_status, revert_status) - ] diff --git a/backend/api/migrations/0037_add_deputy_director_role.py b/backend/api/migrations/0037_add_deputy_director_role.py deleted file mode 100644 index b1ad93855..000000000 --- a/backend/api/migrations/0037_add_deputy_director_role.py +++ /dev/null @@ -1,69 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_role(apps, schema_editor): - """ - Adds the Deputy Director role and assigns permissions to it - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model("api", "Permission") - role = apps.get_model("api", "Role") - role_permission = apps.get_model("api", "RolePermission") - - gov_deputy_director_role = role.objects.using(db_alias).create( - name="GovDeputyDirector", - description="Government Deputy Director", - is_government_role=True, - display_order="8" - ) - - gov_director_permissions = permission.objects.using(db_alias).filter( - role_permissions__role__name="GovDirector" - ).distinct() - - gov_deputy_director_permissions = [] - - for permission in gov_director_permissions: - gov_deputy_director_permissions.append( - role_permission( - role=gov_deputy_director_role, - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create( - gov_deputy_director_permissions - ) - - -def delete_role(apps, schema_editor): - """ - Delete the Deputy Director role and remove the permissions assigned to it - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model("api", "Role") - role_permission = apps.get_model("api", "RolePermission") - - role_permission.objects.using(db_alias).filter( - role__name="GovDeputyDirector" - ).delete() - - role.objects.using(db_alias).filter( - name="GovDeputyDirector" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0036_update_credit_statuses'), - ] - - operations = [ - RunPython(add_role, delete_role) - ] diff --git a/backend/api/migrations/0038_credittradehistory_user_role.py b/backend/api/migrations/0038_credittradehistory_user_role.py deleted file mode 100644 index e70cc9956..000000000 --- a/backend/api/migrations/0038_credittradehistory_user_role.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-10-17 21:54 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0037_add_deputy_director_role'), - ] - - operations = [ - migrations.AddField( - model_name='credittradehistory', - name='user_role', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='roles', to='api.Role'), - ), - ] diff --git a/backend/api/migrations/0039_update_fs_admin_permissions.py b/backend/api/migrations/0039_update_fs_admin_permissions.py deleted file mode 100644 index f0251396f..000000000 --- a/backend/api/migrations/0039_update_fs_admin_permissions.py +++ /dev/null @@ -1,82 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_permissions(apps, schema_editor): - """ - Updates the permissions for FS Admin User - Also add an s to User - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', "Permission") - role = apps.get_model('api', "Role") - role_permission = apps.get_model('api', "RolePermission") - - role.objects.using(db_alias).filter( - name="FSAdmin" - ).update( - description="Managing Users" - ) - - role_permission.objects.using(db_alias).bulk_create([ - role_permission( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="LOGIN") - ), - role_permission( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="ADD_FS_USER") - ), - role_permission( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="EDIT_FUEL_SUPPLIER_USERS") - ), - role_permission( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="VIEW_CREDIT_TRANSFERS") - ) - ]) - - -def revert_permissions(apps, schema_editor): - """ - Reverts the permission back to its previous state for - FS Admin User - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', "Role") - role_permission = apps.get_model('api', "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "LOGIN", - "ADD_FS_USER", - "EDIT_FUEL_SUPPLIER_USERS" - "VIEW_CREDIT_TRANSFERS" - ], - role__name="FSAdmin").delete() - - role.objects.using(db_alias).filter( - name="FSAdmin" - ).update( - description="Managing User" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0038_credittradehistory_user_role'), - ] - - operations = [ - RunPython(update_permissions, revert_permissions) - ] diff --git a/backend/api/migrations/0039_usercreationrequest.py b/backend/api/migrations/0039_usercreationrequest.py deleted file mode 100644 index 30b9ab3c4..000000000 --- a/backend/api/migrations/0039_usercreationrequest.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-10-23 20:43 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0038_credittradehistory_user_role'), - ] - - operations = [ - migrations.CreateModel( - name='UserCreationRequest', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('keycloak_email', models.EmailField(max_length=254, unique=True)), - ('created', models.BooleanField(default=False)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_usercreationrequest_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_usercreationrequest_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='creation_request', to=settings.AUTH_USER_MODEL, unique=True)), - ], - options={ - 'db_table': 'user_creation_request', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0040_auto_20181024_2106.py b/backend/api/migrations/0040_auto_20181024_2106.py deleted file mode 100644 index 00cb9709c..000000000 --- a/backend/api/migrations/0040_auto_20181024_2106.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-10-24 21:06 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0039_usercreationrequest'), - ] - - operations = [ - migrations.RenameField( - model_name='usercreationrequest', - old_name='created', - new_name='is_mapped', - ), - migrations.AlterField( - model_name='usercreationrequest', - name='user', - field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='creation_request', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0041_merge_20181031_2228.py b/backend/api/migrations/0041_merge_20181031_2228.py deleted file mode 100644 index 9530b4ed8..000000000 --- a/backend/api/migrations/0041_merge_20181031_2228.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-10-31 22:28 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0040_auto_20181024_2106'), - ('api', '0039_update_fs_admin_permissions'), - ] - - operations = [ - ] diff --git a/backend/api/migrations/0042_update_credit_trader_role_description.py b/backend/api/migrations/0042_update_credit_trader_role_description.py deleted file mode 100644 index a3affbee8..000000000 --- a/backend/api/migrations/0042_update_credit_trader_role_description.py +++ /dev/null @@ -1,45 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_description(apps, schema_editor): - """ - Updates the role: Credit Trader to Credit Transfers - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', "Role") - - role.objects.using(db_alias).filter( - name="FSUser" - ).update( - description="Credit Transfers" - ) - - -def revert_description(apps, schema_editor): - """ - Reverts the role back to Credit Trader from Credit Transfers - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', "Role") - - role.objects.using(db_alias).filter( - name="FSUser" - ).update( - description="Credit Trader" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0041_merge_20181031_2228'), - ] - - operations = [ - RunPython(update_description, revert_description) - ] diff --git a/backend/api/migrations/0043_edit_user_permission_clean_up.py b/backend/api/migrations/0043_edit_user_permission_clean_up.py deleted file mode 100644 index 3283fe71a..000000000 --- a/backend/api/migrations/0043_edit_user_permission_clean_up.py +++ /dev/null @@ -1,146 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_permissions(apps, schema_editor): - """ - Removes similar looking permissions to remove - redundancy - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', "Permission") - role = apps.get_model('api', "Role") - role_permission = apps.get_model('api', "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "ADD_FS_USER", - "EDIT_FUEL_SUPPLIER_USERS" - ]).delete() - - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "USER_MANAGEMENT" - ], - role__name__in=[ - "GovUser", - "GovDirector", - "GovDeputyDirector" - ]).delete() - - role_permission.objects.using(db_alias).create( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="USER_MANAGEMENT") - ) - - permission.objects.using(db_alias).filter( - code__in=[ - "ADD_FS_USER", - "EDIT_FUEL_SUPPLIER_USERS" - ] - ).delete() - - permission.objects.using(db_alias).filter( - code="EDIT_FUEL_SUPPLIERS" - ).update( - name="Edit Organization Information", - description="Allows the user to create and update organizations" - ) - - -def revert_permissions(apps, schema_editor): - """ - Adds the permissions back - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', "Permission") - role = apps.get_model('api', "Role") - role_permission = apps.get_model('api', "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "USER_MANAGEMENT" - ], - role__name__in=[ - "FSAdmin" - ]).delete() - - permission.objects.using(db_alias).bulk_create([ - permission( - code="ADD_FS_USER", - description="Add Fuel Supplier User", - name="Add Fuel Supplier User" - ), - permission( - code="EDIT_FUEL_SUPPLIER_USERS", - description="Add Fuel Supplier User", - name="Edit Fuel Supplier Users' Information" - ) - ]) - - role_permission.objects.using(db_alias).bulk_create([ - role_permission( - role=role.objects.using(db_alias).get(name="GovUser"), - permission=permission.objects.using(db_alias).get( - code="USER_MANAGEMENT") - ), - role_permission( - role=role.objects.using(db_alias).get(name="GovDirector"), - permission=permission.objects.using(db_alias).get( - code="USER_MANAGEMENT") - ), - role_permission( - role=role.objects.using(db_alias).get(name="GovDeputyDirector"), - permission=permission.objects.using(db_alias).get( - code="USER_MANAGEMENT") - ), - role_permission( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="ADD_FS_USER") - ), - role_permission( - role=role.objects.using(db_alias).get(name="Admin"), - permission=permission.objects.using(db_alias).get( - code="EDIT_FUEL_SUPPLIER_USERS") - ), - role_permission( - role=role.objects.using(db_alias).get(name="GovUser"), - permission=permission.objects.using(db_alias).get( - code="EDIT_FUEL_SUPPLIER_USERS") - ), - role_permission( - role=role.objects.using(db_alias).get(name="GovDirector"), - permission=permission.objects.using(db_alias).get( - code="EDIT_FUEL_SUPPLIER_USERS") - ), - role_permission( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="EDIT_FUEL_SUPPLIER_USERS") - ) - ]) - - permission.objects.using(db_alias).filter( - code="EDIT_FUEL_SUPPLIERS" - ).update( - name="Edit Fuel Suppliers", - description="Gives the user access to create and update " - "fuel suppliers" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0042_update_credit_trader_role_description'), - ] - - operations = [ - RunPython(update_permissions, revert_permissions) - ] diff --git a/backend/api/migrations/0044_auto_20181122_2212.py b/backend/api/migrations/0044_auto_20181122_2212.py deleted file mode 100644 index 99c5d6e57..000000000 --- a/backend/api/migrations/0044_auto_20181122_2212.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-11-22 22:12 -from __future__ import unicode_literals - -import api.notifications.notification_types -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0043_edit_user_permission_clean_up'), - ] - - operations = [ - migrations.AlterField( - model_name='notificationsubscription', - name='notification_type', - field=models.CharField(choices=[(api.notifications.notification_types.NotificationType('Credit Transfer Proposal Created'), 'Credit Transfer Proposal Created'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 1/2'), 'Credit Transfer Proposal Signed 1/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 2/2'), 'Credit Transfer Proposal Signed 2/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Refused'), 'Credit Transfer Proposal Refused'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Accepted'), 'Credit Transfer Proposal Accepted'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Approval'), 'Credit Transfer Proposal Recommended For Approval'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Declination'), 'Credit Transfer Proposal Recommended For Declination'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Declined'), 'Credit Transfer Proposal Declined'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Approved'), 'Credit Transfer Proposal Approved'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Rescinded'), 'Credit Transfer Proposal Rescinded'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Comment Created Or Updated'), 'Credit Transfer Proposal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Internal Comment Created Or Updated'), 'Credit Transfer Proposal Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Created'), 'PVR Created'), (api.notifications.notification_types.NotificationType('PVR Recommended For Approval'), 'PVR Recommended For Approval'), (api.notifications.notification_types.NotificationType('PVR Rescinded'), 'PVR Rescinded'), (api.notifications.notification_types.NotificationType('PVR Pulled Back'), 'PVR Pulled Back'), (api.notifications.notification_types.NotificationType('PVR Declined'), 'PVR Declined'), (api.notifications.notification_types.NotificationType('PVR Approved'), 'PVR Approved'), (api.notifications.notification_types.NotificationType('PVR Comment Created Or Updated'), 'PVR Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Internal Comment Created Or Updated'), 'PVR Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Returned to Analyst'), 'PVR Returned to Analyst')], max_length=128), - ), - ] diff --git a/backend/api/migrations/0045_documents.py b/backend/api/migrations/0045_documents.py deleted file mode 100644 index cc677c5a3..000000000 --- a/backend/api/migrations/0045_documents.py +++ /dev/null @@ -1,218 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-11-29 00:23 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0044_auto_20181122_2212'), - ] - - operations = [ - migrations.CreateModel( - name='Document', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('url', models.URLField()), - ('size', models.BigIntegerField(default=0)), - ('mime_type', models.CharField(max_length=255)), - ('title', models.CharField(max_length=120)), - ], - options={ - 'db_table': 'document', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='DocumentCategory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('name', models.CharField(blank=True, max_length=120, null=True, unique=True)), - ], - options={ - 'db_table': 'document_category', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='DocumentHistory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('title', models.CharField(max_length=120)), - ], - options={ - 'db_table': 'document_history', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='DocumentStatus', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('status', models.CharField(blank=True, max_length=25, null=True, unique=True)), - ], - options={ - 'db_table': 'document_status', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='DocumentType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('the_type', models.CharField(blank=True, max_length=100, null=True, unique=True)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='types', to='api.DocumentCategory')), - ], - options={ - 'db_table': 'document_type', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.RemoveField( - model_name='organizationattachment', - name='create_user', - ), - migrations.RemoveField( - model_name='organizationattachment', - name='organization', - ), - migrations.RemoveField( - model_name='organizationattachment', - name='update_user', - ), - migrations.RemoveField( - model_name='user', - name='effective_date', - ), - migrations.RemoveField( - model_name='user', - name='expiration_date', - ), - migrations.AlterField( - model_name='organizationtype', - name='display_order', - field=models.IntegerField(default=0), - preserve_default=False, - ), - migrations.DeleteModel( - name='OrganizationAttachment', - ), - migrations.AddField( - model_name='documenttype', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documenttype_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documenttype', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documenttype_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documentstatus', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentstatus_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documentstatus', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentstatus_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documenthistory', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documenthistory_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documenthistory', - name='creating_organization', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.Organization'), - ), - migrations.AddField( - model_name='documenthistory', - name='document', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='history_entries', to='api.Document'), - ), - migrations.AddField( - model_name='documenthistory', - name='modifying_user', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='users', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documenthistory', - name='modifying_user_role', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='role', to='api.Role'), - ), - migrations.AddField( - model_name='documenthistory', - name='status', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.DocumentStatus'), - ), - migrations.AddField( - model_name='documenthistory', - name='type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.DocumentType'), - ), - migrations.AddField( - model_name='documenthistory', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documenthistory_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documentcategory', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentcategory_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='documentcategory', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentcategory_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='document', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_document_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='document', - name='creating_organization', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.Organization'), - ), - migrations.AddField( - model_name='document', - name='status', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.DocumentStatus'), - ), - migrations.AddField( - model_name='document', - name='type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.DocumentType'), - ), - migrations.AddField( - model_name='document', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_document_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0046_document_data_load.py b/backend/api/migrations/0046_document_data_load.py deleted file mode 100644 index 681138ffd..000000000 --- a/backend/api/migrations/0046_document_data_load.py +++ /dev/null @@ -1,140 +0,0 @@ -from datetime import datetime - -from django.db import migrations, IntegrityError -from django.db.migrations import RunPython - - -def create_initial_data(apps, schema_editor): - """Load initial data (previously stored in fixtures) - This is for core (essential) data only -- operational data should be inserted with scripts - - This script is designed to look for existing data and add any missing elements, without - disrupting existing data, or load a database from nothing (as for testing) - - It is idempotent and irreversible - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately versioned - # for this migration (so this shouldn't ever need to be maintained if fields change) - doc_status = apps.get_model("api", "DocumentStatus") - doc_type = apps.get_model("api", "DocumentType") - doc_cat = apps.get_model("api", "DocumentCategory") - role = apps.get_model("api", "Role") - permission = apps.get_model("api", "Permission") - role_permission = apps.get_model("api", "RolePermission") - - doc_statuses = [ - doc_status(status='Draft', - display_order=1, - effective_date='2017-01-01'), - doc_status(status='Submitted', - display_order=2, - effective_date='2017-01-01'), - doc_status(status='Received', - display_order=3, - effective_date='2017-01-01') - ] - - for new_doc_status in doc_statuses: - if not doc_status.objects.using(db_alias).filter(status=new_doc_status.status).exists(): - doc_status.objects.using(db_alias).bulk_create([new_doc_status]) - else: - print('skipping existing document status {}'.format(new_doc_status.status)) - - doc_cats = [ - doc_cat( - name='Part 3 Agreements', - display_order=1 - ) - ] - - for new_doc_cat in doc_cats: - if not doc_cat.objects.using(db_alias).filter(name=new_doc_cat.name).exists(): - doc_cat.objects.using(db_alias).bulk_create([new_doc_cat]) - else: - print('skipping existing document category {}'.format(new_doc_cat.name)) - - doc_types = [ - doc_type(the_type='Application', - effective_date='2017-01-01', - category=doc_cat.objects.get(name='Part 3 Agreements') - ), - doc_type(the_type='Evidence', - effective_date='2017-01-01', - category=doc_cat.objects.get(name='Part 3 Agreements') - ) - ] - - for new_doc_type in doc_types: - if not doc_type.objects.using(db_alias).filter(the_type=new_doc_type.the_type).exists(): - doc_type.objects.using(db_alias).bulk_create([new_doc_type]) - else: - print('skipping existing document type {}'.format(new_doc_type.the_type)) - - permissions = [ - permission(code='DOCUMENTS_CREATE_DRAFT', name='Submit draft documents', - description='Submit secure documents with draft status'), - permission(code='DOCUMENTS_SUBMIT', name='Submit documents', - description='Submit secure documents'), - permission(code='DOCUMENTS_GOVERNMENT_REVIEW', name='Review documents', - description='Government can accept documents for review'), - permission(code='DOCUMENTS_VIEW', name='View documents', - description='View secure documents'), - ] - - for new_permission in permissions: - if not permission.objects.using(db_alias).filter(code=new_permission.code).exists(): - permission.objects.using(db_alias).bulk_create([new_permission]) - else: - print('skipping existing permission {}'.format(new_permission.code)) - - roles = [ - role(name='FSDoc', description='A Fuel Supplier user with authority to view documents and submit drafts', - is_government_role=True, display_order=10), - role(name='FSDocSubmit', description='A Fuel Supplier user with authority to submit documents', - is_government_role=False, display_order=11) - ] - - for new_role in roles: - if not role.objects.using(db_alias).filter(name=new_role.name).exists(): - role.objects.using(db_alias).bulk_create([new_role]) - else: - print('skipping existing role {}'.format(new_role.name)) - - role_permissions = [ - role_permission(role=role.objects.using(db_alias).get(name='FSDoc'), - permission=permission.objects.using(db_alias).get(code='DOCUMENTS_VIEW')), - role_permission(role=role.objects.using(db_alias).get(name='FSDoc'), - permission=permission.objects.using(db_alias).get(code='DOCUMENTS_CREATE_DRAFT')), - role_permission(role=role.objects.using(db_alias).get(name='FSDocSubmit'), - permission=permission.objects.using(db_alias).get(code='DOCUMENTS_VIEW')), - role_permission(role=role.objects.using(db_alias).get(name='FSDocSubmit'), - permission=permission.objects.using(db_alias).get(code='DOCUMENTS_CREATE_DRAFT')), - role_permission(role=role.objects.using(db_alias).get(name='FSDocSubmit'), - permission=permission.objects.using(db_alias).get(code='DOCUMENTS_SUBMIT')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='DOCUMENTS_VIEW')), - role_permission(role=role.objects.using(db_alias).get(name='GovUser'), - permission=permission.objects.using(db_alias).get(code='DOCUMENTS_GOVERNMENT_REVIEW')) - ] - - for new_role_permission in role_permissions: - if not role_permission.objects.using(db_alias).filter( - role=role.objects.using(db_alias).get(name=new_role_permission.role.name), - permission=permission.objects.using(db_alias).get(code=new_role_permission.permission.code)).exists(): - role_permission.objects.using(db_alias).bulk_create([new_role_permission]) - else: - print('skipping existing role<->permission {}:{}'.format(new_role_permission.role.name, - new_role_permission.permission.code)) - - -class Migration(migrations.Migration): - dependencies = [ - ('api', '0045_documents'), - ] - - operations = [ - # This is a one-way trip - RunPython(create_initial_data, reverse_code=None) - ] diff --git a/backend/api/migrations/0047_auto_20181205_1716.py b/backend/api/migrations/0047_auto_20181205_1716.py deleted file mode 100644 index f892878f6..000000000 --- a/backend/api/migrations/0047_auto_20181205_1716.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-12-05 17:16 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0046_document_data_load'), - ] - - operations = [ - migrations.AlterField( - model_name='user', - name='cell_phone', - field=models.CharField(blank=True, max_length=17, null=True), - ), - migrations.AlterField( - model_name='user', - name='phone', - field=models.CharField(blank=True, max_length=17, null=True), - ), - ] diff --git a/backend/api/migrations/0048_auto_20181213_2313.py b/backend/api/migrations/0048_auto_20181213_2313.py deleted file mode 100644 index edb0e5def..000000000 --- a/backend/api/migrations/0048_auto_20181213_2313.py +++ /dev/null @@ -1,79 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-12-13 23:13 -from __future__ import unicode_literals -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - -import db_comments.model_mixins - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0047_auto_20181205_1716'), - ] - - operations = [ - migrations.CreateModel( - name='DocumentFileAttachment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('url', models.URLField()), - ('size', models.BigIntegerField(default=0)), - ('mime_type', models.CharField(max_length=255)), - ('security_scan_status', models.CharField(choices=[('NOT RUN', 'Not Run'), ('IN PROGRESS', 'In Progress'), ('PASS', 'Passed'), ('FAIL', 'Failed')], default='NOT RUN', max_length=20)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentfileattachment_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'document_file', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.RemoveField( - model_name='document', - name='mime_type', - ), - migrations.RemoveField( - model_name='document', - name='size', - ), - migrations.RemoveField( - model_name='document', - name='url', - ), - migrations.AddField( - model_name='document', - name='comment', - field=models.CharField(blank=True, max_length=1024, null=True), - ), - migrations.AddField( - model_name='document', - name='compliance_period', - field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='api.CompliancePeriod'), - preserve_default=False, - ), - migrations.AddField( - model_name='documenthistory', - name='comment', - field=models.CharField(blank=True, max_length=1024, null=True), - ), - migrations.AddField( - model_name='documenthistory', - name='compliance_period', - field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='api.CompliancePeriod'), - preserve_default=False, - ), - migrations.AddField( - model_name='documentfileattachment', - name='document', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='attachments', to='api.Document'), - ), - migrations.AddField( - model_name='documentfileattachment', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentfileattachment_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0049_auto_20181217_1824.py b/backend/api/migrations/0049_auto_20181217_1824.py deleted file mode 100644 index 609cb8e27..000000000 --- a/backend/api/migrations/0049_auto_20181217_1824.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-12-17 18:24 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0048_auto_20181213_2313'), - ] - - operations = [ - migrations.AlterField( - model_name='documentfileattachment', - name='url', - field=models.URLField(max_length=2048), - ), - ] diff --git a/backend/api/migrations/0050_documentfileattachment_filename.py b/backend/api/migrations/0050_documentfileattachment_filename.py deleted file mode 100644 index b9f5f0115..000000000 --- a/backend/api/migrations/0050_documentfileattachment_filename.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-12-18 01:36 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0049_auto_20181217_1824'), - ] - - operations = [ - migrations.AddField( - model_name='documentfileattachment', - name='filename', - field=models.CharField(default=django.utils.timezone.now, max_length=260), - preserve_default=False, - ), - ] diff --git a/backend/api/migrations/0051_auto_20181218_1654.py b/backend/api/migrations/0051_auto_20181218_1654.py deleted file mode 100644 index 58de77cb1..000000000 --- a/backend/api/migrations/0051_auto_20181218_1654.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-12-18 16:54 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0050_documentfileattachment_filename'), - ] - - operations = [ - migrations.RemoveField( - model_name='document', - name='creating_organization', - ), - migrations.RemoveField( - model_name='documenthistory', - name='creating_organization', - ), - ] diff --git a/backend/api/migrations/0052_document_data_update.py b/backend/api/migrations/0052_document_data_update.py deleted file mode 100644 index 33116f450..000000000 --- a/backend/api/migrations/0052_document_data_update.py +++ /dev/null @@ -1,101 +0,0 @@ -from datetime import datetime - -from django.db import migrations -from django.db.migrations import RunPython - - -def update_document_types(apps, schema_editor): - """ - Adds the description for Application and Evidence. - Add 'Other' Category - Adds Fuel Supply Records and Other - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - doc_cat = apps.get_model('api', 'DocumentCategory') - doc_type = apps.get_model('api', 'DocumentType') - - doc_category = doc_cat( - name='Other', - display_order=2 - ) - - if not doc_cat.objects.using(db_alias).filter( - name=doc_category.name).exists(): - doc_cat.objects.using(db_alias).bulk_create([doc_category]) - - doc_types = [ - doc_type(the_type='Application', - description='P3A Application', - effective_date='2017-01-01', - category=doc_cat.objects.get(name='Part 3 Agreements') - ), - doc_type(the_type='Evidence', - description='P3A Milestone Evidence', - effective_date='2017-01-01', - category=doc_cat.objects.get(name='Part 3 Agreements') - ), - doc_type(the_type='Records', - description='Fuel Supply Records', - effective_date='2017-01-01', - category=doc_cat.objects.get(name='Other') - ), - doc_type(the_type='Other', - description='Other', - effective_date='2017-01-01', - category=doc_cat.objects.get(name='Other') - ) - ] - - for new_doc_type in doc_types: - if not doc_type.objects.using(db_alias).filter( - the_type=new_doc_type.the_type).exists(): - doc_type.objects.using(db_alias).bulk_create([new_doc_type]) - else: - doc_type.objects.using(db_alias).filter( - the_type=new_doc_type.the_type).update( - the_type=new_doc_type.the_type, - description=new_doc_type.description, - effective_date=new_doc_type.effective_date, - category=new_doc_type.category) - - -def revert_document_types(apps, schema_editor): - """ - Reverts the changes to document types. - Removes the description for Application Evidence. - Removes 'Other' Category - Removes Fuel Supply Records and Other - """ - db_alias = schema_editor.connection.alias - - doc_cat = apps.get_model('api', 'DocumentCategory') - doc_type = apps.get_model('api', 'DocumentType') - - doc_type.objects.using(db_alias).filter( - category=doc_cat.objects.get(name='Other')).delete() - - doc_type.objects.using(db_alias).filter( - category=doc_cat.objects.get( - name='Part 3 Agreements')).update( - description='' - ) - - doc_cat.objects.using(db_alias).filter( - name='Other').delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0051_auto_20181218_1654'), - ] - - operations = [ - RunPython(update_document_types, revert_document_types) - ] diff --git a/backend/api/migrations/0053_auto_20181220_1644.py b/backend/api/migrations/0053_auto_20181220_1644.py deleted file mode 100644 index c254578df..000000000 --- a/backend/api/migrations/0053_auto_20181220_1644.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-12-20 16:44 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0052_document_data_update'), - ] - - operations = [ - migrations.RenameField( - model_name='documenthistory', - old_name='modifying_user_role', - new_name='user_role', - ), - migrations.RemoveField( - model_name='documenthistory', - name='modifying_user', - ), - ] diff --git a/backend/api/migrations/0054_organization_descriptions_update.py b/backend/api/migrations/0054_organization_descriptions_update.py deleted file mode 100644 index 84b689d80..000000000 --- a/backend/api/migrations/0054_organization_descriptions_update.py +++ /dev/null @@ -1,115 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_organization_descriptions(apps, schema_editor): - """ - Updates the descriptions for Organization Status and Types - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - organization_actions_type = apps.get_model( - 'api', 'OrganizationActionsType') - organization_status = apps.get_model('api', 'OrganizationStatus') - organization_type = apps.get_model('api', 'OrganizationType') - - organization_actions_type.objects.using(db_alias).filter( - the_type="Buy And Sell" - ).update( - description="Permitted to Buy and Sell Low Carbon Fuel Credits." - ) - - organization_actions_type.objects.using(db_alias).filter( - the_type="Sell Only" - ).update( - description="Permitted to only Sell Low Carbon Fuel Credits." - ) - - organization_actions_type.objects.using(db_alias).filter( - the_type="None" - ).update( - description="Not Permitted to Buy and Sell Low Carbon Fuel Credits." - ) - - organization_status.objects.using(db_alias).filter( - status="Active").update( - description="Active" - ) - - organization_status.objects.using(db_alias).filter( - status="Archived").update( - description="Inactive" - ) - - organization_type.objects.using(db_alias).filter( - type="Part3FuelSupplier").update( - description="Part 3 Fuel Supplier" - ) - - -def revert_organization_descriptions(apps, schema_editor): - """ - Reverts the descriptions for Organization Status and Types - """ - db_alias = schema_editor.connection.alias - - organization_actions_type = apps.get_model( - 'api', 'OrganizationActionsType') - organization_status = apps.get_model('api', 'OrganizationStatus') - organization_type = apps.get_model('api', 'OrganizationType') - - organization_actions_type.objects.using(db_alias).filter( - the_type="Buy And Sell" - ).update( - description="An Organization permitted to both Buy and Sell " - "Low Carbon Credits." - ) - - organization_actions_type.objects.using(db_alias).filter( - the_type="Sell Only" - ).update( - description="An Organization permitted to only to Sell Low " - "Carbon Credits." - ) - - organization_actions_type.objects.using(db_alias).filter( - the_type="None" - ).update( - description="An Organization not currently permitted to " - "either Buy and Sell Low Carbon Credits." - ) - - organization_status.objects.using(db_alias).filter( - status="Active").update( - description="The Fuel Supplier is an active participant " - "in the Low Carbon Credits trading market." - ) - - organization_status.objects.using(db_alias).filter( - status="Archived").update( - description="The Fuel Supplier has been archived and is " - "no longer a participant in theLow Carbon " - "Credits trading market." - ) - - organization_type.objects.using(db_alias).filter( - type="Part3FuelSupplier").update( - description="A Part 3 Fuel Supplier who can do credit transfers" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0053_auto_20181220_1644'), - ] - - operations = [ - RunPython(update_organization_descriptions, - revert_organization_descriptions) - ] diff --git a/backend/api/migrations/0055_role_permission_descriptions.py b/backend/api/migrations/0055_role_permission_descriptions.py deleted file mode 100644 index 20e2273a2..000000000 --- a/backend/api/migrations/0055_role_permission_descriptions.py +++ /dev/null @@ -1,411 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_permission_names(apps, schema_editor): - """ - Updates the permission names so they make more sense - when they're being displayed to the user. - Shortens some of the Role names - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - permission.objects.using(db_alias).filter( - code="APPROVE_CREDIT_TRANSFER" - ).update( - name="Approve Credit Transaction", - description="The ability to make a statuatory decision by " - "approving a credit transaction (Credit Transfer " - "Proposal, Part 3 Award, Validation, and Reduction)." - ) - - permission.objects.using(db_alias).filter( - code="ASSIGN_FS_ROLES" - ).update( - name="Assign Roles to Fuel Supplier Users", - description="The ability to assign roles to the users within " - "an organization." - ) - - permission.objects.using(db_alias).filter( - code="ASSIGN_GOVERNMENT_ROLES" - ).update( - name="Assign Government Roles", - description="The ability to assign roles to government users." - ) - - permission.objects.using(db_alias).filter( - code="DECLINE_CREDIT_TRANSFER" - ).update( - name="Decline to Approve Credit Transaction", - description="The ability to make a statuatory decision by declining " - "to approve a credit transaction (Credit Transfer " - "Proposal, Part 3 Award, Validation, and Reduction)." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_CREATE_DRAFT" - ).update( - name="Upload documents into a draft state", - description="Securely upload documents and save as a draft " - "(not visible to Government)." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_GOVERNMENT_REVIEW" - ).update( - name="Review uploaded documents", - description="The ability to review uploaded documents (mark " - "them as reviewed status)." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_SUBMIT" - ).update( - name="Upload documents", - description="Securely upload and submit documents." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_VIEW" - ).update( - name="View uploaded documents", - description="View and download documents that have been " - "securely uploaded." - ) - - permission.objects.using(db_alias).filter( - code="EDIT_COMPLIANCE_PERIODS" - ).update( - description="The ability to edit compliance periods." - ) - - permission.objects.using(db_alias).filter( - code="EDIT_FUEL_SUPPLIERS" - ).update( - name="Organization Management", - description="The ability to create and update organizations." - ) - - permission.objects.using(db_alias).filter( - code="EDIT_PRIVILEGED_COMMENTS" - ).update( - description="The ability to create and update privileged comments " - "that are only visible to government users." - ) - - permission.objects.using(db_alias).filter( - code="PROPOSE_CREDIT_TRANSFER" - ).update( - name="Create New Credit Transfer Proposal", - description="The ability to create a new Credit Transfer Proposal. " - "For Government users, this permission grants the " - "ability to create a New Credit Transaction (Part 3 " - "Award, Validation, Reduction)." - ) - - permission.objects.using(db_alias).filter( - code="RECOMMEND_CREDIT_TRANSFER" - ).update( - name="Recommend Credit Transactions", - description="The ability to either recommend or not recommend " - "approval of a credit transaction (Credit Transfer " - "Proposal, Part 3 Award, Validation, and Reduction)." - ) - - permission.objects.using(db_alias).filter( - code="REFUSE_CREDIT_TRANSFER" - ).update( - name="Refuse a Credit Transfer Proposal", - description="The ability to refuse a Credit Transfer Proposal " - "sent to your organization by another fuel supplier." - ) - - permission.objects.using(db_alias).filter( - code="RESCIND_CREDIT_TRANSFER" - ).update( - name="Rescind a Credit Transfer Proposal", - description="The ability to rescind or otherwise cancel a Credit " - "Transfer Proposal. For Government users, this " - "permission grants the ability to recall a recommended " - "Credit Transaction (Part 3 Award, Validation, " - "Reduction) as draft." - ) - - permission.objects.using(db_alias).filter( - code="SIGN_CREDIT_TRANSFER" - ).update( - name="Sign a Credit Transfer Proposal", - description="The ability to sign and execute a Credit Transfer " - "Proposal." - ) - - permission.objects.using(db_alias).filter( - code="USER_MANAGEMENT" - ).update( - description="The ability to add new users and edit existing users" - ) - - permission.objects.using(db_alias).filter( - code="VIEW_APPROVED_CREDIT_TRANSFERS" - ).update( - name="View Recorded Credit Transactions", - description="The ability to view queued or recorded transactions " - "within the Historical Data Entry tool prior to those " - "transactions being committed." - ) - - permission.objects.using(db_alias).filter( - code="VIEW_CREDIT_TRANSFERS" - ).update( - name="View Credit Transactions", - description="The ability to view credit transaction entries, " - "including Credit Transfer Proposals, Part 3 Awards, " - "Validations, and Reductions." - ) - - permission.objects.using(db_alias).filter( - code="VIEW_FUEL_SUPPLIERS" - ).update( - name="View Fuel Supplier Information", - description="The ability to view all fuel supplier information, " - "including sensitive information (e.g. credit balances)." - ) - - permission.objects.using(db_alias).filter( - code="VIEW_PRIVILEGED_COMMENTS" - ).update( - description="The ability to view privileged comments (comments that " - "are only visible to government users)." - ) - - permission.objects.using(db_alias).filter( - code="USE_HISTORICAL_DATA_ENTRY" - ).update( - description="Allows the user to enter credit transactions that " - "have already been approved outside of TFRS." - ) - - role.objects.using(db_alias).filter( - name="FSDoc" - ).update( - description="Document Upload (Government)" - ) - - role.objects.using(db_alias).filter( - name="FSDocSubmit" - ).update( - description="Document Upload" - ) - - role_permission.objects.using(db_alias).create( - role=role.objects.using(db_alias).get(name="FSNoAccess"), - permission=permission.objects.using(db_alias).get( - code="LOGIN") - ) - - -def revert_permission_names(apps, schema_editor): - """ - Reverts the names to their previous states - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - permission.objects.using(db_alias).filter( - code="APPROVE_CREDIT_TRANSFER" - ).update( - name="Approve Transfer", - description="Approve Transfer" - ) - - permission.objects.using(db_alias).filter( - code="ASSIGN_FS_ROLES" - ).update( - name="Assign Fuel Supplier Roles", - description="Allows the user to assign fuel supplier " - "roles to users" - ) - - permission.objects.using(db_alias).filter( - code="ASSIGN_GOVERNMENT_ROLES" - ).update( - name="Assign Government Roles", - description="Allows the user to assign government roles to users" - ) - - permission.objects.using(db_alias).filter( - code="DECLINE_CREDIT_TRANSFER" - ).update( - name="Decline Transfer", - description="Decline Transfer" - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_GOVERNMENT_REVIEW" - ).update( - name="Review documents", - description="Government can accept documents for review" - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_CREATE_DRAFT" - ).update( - name="Submit draft documents", - description="Submit secure documents with draft status" - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_SUBMIT" - ).update( - name="Submit documents", - description="Submit secure documents" - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_VIEW" - ).update( - name="View documents", - description="View secure documents" - ) - - permission.objects.using(db_alias).filter( - code="EDIT_COMPLIANCE_PERIODS" - ).update( - description="Gives the user access to edit compliance periods" - ) - - permission.objects.using(db_alias).filter( - code="EDIT_FUEL_SUPPLIERS" - ).update( - name="Edit Organization Information", - description="Allows the user to create and update organizations" - ) - - permission.objects.using(db_alias).filter( - code="EDIT_PRIVILEGED_COMMENTS" - ).update( - description="Create and Update Privileged Comments" - ) - - permission.objects.using(db_alias).filter( - code="PROPOSE_CREDIT_TRANSFER" - ).update( - name="Propose Credit Transfer", - description="Propose Credit Transfer" - ) - - permission.objects.using(db_alias).filter( - code="RECOMMEND_CREDIT_TRANSFER" - ).update( - name="Recommend Credit Transfer", - description="Recommend/Not Recommend Credit Transfer" - ) - - permission.objects.using(db_alias).filter( - code="REFUSE_CREDIT_TRANSFER" - ).update( - name="Refuse Credit Transfer", - description="Refuse Credit Transfer" - ) - - permission.objects.using(db_alias).filter( - code="RESCIND_CREDIT_TRANSFER" - ).update( - name="Rescind Credit Transfer", - description="Rescind Credit Transfer" - ) - - permission.objects.using(db_alias).filter( - code="SIGN_CREDIT_TRANSFER" - ).update( - name="Sign Credit Transfer", - description="Sign Credit Transfer" - ) - - permission.objects.using(db_alias).filter( - code="USE_HISTORICAL_DATA_ENTRY" - ).update( - description="Allows the user to use the functions of Historical " - "Data Entry" - ) - - permission.objects.using(db_alias).filter( - code="USER_MANAGEMENT" - ).update( - description="Gives the user access to the User Management screens" - ) - - permission.objects.using(db_alias).filter( - code="VIEW_APPROVED_CREDIT_TRANSFERS" - ).update( - name="View Approved Credit Transfers", - description="View Approved Credit Transfers" - ) - - permission.objects.using(db_alias).filter( - code="VIEW_CREDIT_TRANSFERS" - ).update( - name="View Credit Transfers", - description="View Credit Transfers" - ) - - permission.objects.using(db_alias).filter( - code="VIEW_FUEL_SUPPLIERS" - ).update( - name="View Fuel Suppliers", - description="View Fuel Suppliers" - ) - - permission.objects.using(db_alias).filter( - code="VIEW_PRIVILEGED_COMMENTS" - ).update( - description="View (Read) Privileged Comments" - ) - - role.objects.using(db_alias).filter( - name="FSDoc" - ).update( - description="A Fuel Supplier user with authority to view " - "documents and submit drafts." - ) - - role.objects.using(db_alias).filter( - name="FSDocSubmit" - ).update( - description="A Fuel Supplier user with authority to submit documents" - ) - - role_permission.objects.using(db_alias).filter( - role=role.objects.using(db_alias).get(name="FSNoAccess"), - permission=permission.objects.using(db_alias).get(code="LOGIN") - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0054_organization_descriptions_update'), - ] - - operations = [ - RunPython(update_permission_names, - revert_permission_names) - ] diff --git a/backend/api/migrations/0056_auto_20190103_2227.py b/backend/api/migrations/0056_auto_20190103_2227.py deleted file mode 100644 index f2ee698b6..000000000 --- a/backend/api/migrations/0056_auto_20190103_2227.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.17 on 2019-01-03 22:27 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0055_role_permission_descriptions'), - ] - - operations = [ - migrations.AlterField( - model_name='User', - name='display_name', - field=models.CharField(db_column='display_name', blank=True, null=True, max_length=500)), - migrations.RenameField( - model_name='User', - old_name='display_name', - new_name='_display_name' - ) - ] diff --git a/backend/api/migrations/0057_auto_20190103_2247.py b/backend/api/migrations/0057_auto_20190103_2247.py deleted file mode 100644 index 579523552..000000000 --- a/backend/api/migrations/0057_auto_20190103_2247.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.17 on 2019-01-03 22:47 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0056_auto_20190103_2227'), - ] - - operations = [ - migrations.RemoveField( - model_name='credittradehistory', - name='credit_trade_update_time', - ), - migrations.RemoveField( - model_name='credittradehistory', - name='user', - ), - ] diff --git a/backend/api/migrations/0058_auto_20190103_2258.py b/backend/api/migrations/0058_auto_20190103_2258.py deleted file mode 100644 index b946bd330..000000000 --- a/backend/api/migrations/0058_auto_20190103_2258.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.17 on 2019-01-03 22:58 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0057_auto_20190103_2247'), - ] - - operations = [ - migrations.RemoveField( - model_name='user', - name='authorization_directory', - ), - migrations.RemoveField( - model_name='user', - name='authorization_email', - ), - migrations.RemoveField( - model_name='user', - name='authorization_guid', - ), - migrations.RemoveField( - model_name='user', - name='authorization_id', - ), - ] diff --git a/backend/api/migrations/0059_comment_permissions.py b/backend/api/migrations/0059_comment_permissions.py deleted file mode 100644 index ec2b5d2b6..000000000 --- a/backend/api/migrations/0059_comment_permissions.py +++ /dev/null @@ -1,80 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_comment_permission(apps, schema_editor): - """ - Adds the Add Comment permission and attach it to all roles - except FSNoAccess - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - comment_permission = permission.objects.using(db_alias).create( - code="ADD_COMMENT", - name="Add Comment", - description="The ability to add comments to credit transactions " - "(Credit Transfer Proposal, Part 3 Award, Validation, " - "and Reduction)." - ) - - role_permissions = [] - - roles = role.objects.using(db_alias).filter(name__in=[ - "Admin", "FSAdmin", "FSDoc", "FSDocSubmit", "FSManager", "FSUser", - "GovDeputyDirector", "GovDirector", "GovUser" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=comment_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_comment_permission(apps, schema_editor): - """ - Removes the Add Comment permission and all its links to the roles - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - role_permission.objects.using(db_alias).filter( - permission=permission.objects.using(db_alias).get(code="ADD_COMMENT") - ).delete() - - permission.objects.using(db_alias).filter( - code="ADD_COMMENT" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0058_auto_20190103_2258'), - ] - - operations = [ - RunPython(add_comment_permission, - remove_comment_permission) - ] diff --git a/backend/api/migrations/0060_documentcomment.py b/backend/api/migrations/0060_documentcomment.py deleted file mode 100644 index 60666e89f..000000000 --- a/backend/api/migrations/0060_documentcomment.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2019-01-09 18:53 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0059_comment_permissions'), - ] - - operations = [ - migrations.CreateModel( - name='DocumentComment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('comment', models.CharField(blank=True, db_column='document_comment', max_length=4000, null=True)), - ('privileged_access', models.BooleanField(db_column='is_privileged_access', default=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentcomment_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('document', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='document_comments', to='api.Document')), - ('document_history_at_creation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='document_comments', to='api.DocumentHistory')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentcomment_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'document_comments', - 'ordering': ['create_timestamp'], - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0061_auto_20190110_2139.py b/backend/api/migrations/0061_auto_20190110_2139.py deleted file mode 100644 index 724063113..000000000 --- a/backend/api/migrations/0061_auto_20190110_2139.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2019-01-10 21:39 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0060_documentcomment'), - ] - - operations = [ - migrations.RemoveField( - model_name='document', - name='comment', - ), - migrations.RemoveField( - model_name='documenthistory', - name='comment', - ), - ] diff --git a/backend/api/migrations/0062_auto_20190115_1640.py b/backend/api/migrations/0062_auto_20190115_1640.py deleted file mode 100644 index 0fe199faa..000000000 --- a/backend/api/migrations/0062_auto_20190115_1640.py +++ /dev/null @@ -1,52 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2019-01-15 16:40 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0061_auto_20190110_2139'), - ] - - operations = [ - migrations.CreateModel( - name='DocumentMilestone', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('milestone', models.CharField(blank=True, max_length=1000, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentmilestone_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'document_milestone', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AddField( - model_name='document', - name='record_number', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AddField( - model_name='documenthistory', - name='record_number', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AddField( - model_name='documentmilestone', - name='document', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='milestones', to='api.Document'), - ), - migrations.AddField( - model_name='documentmilestone', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentmilestone_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0063_documents_permission_update.py b/backend/api/migrations/0063_documents_permission_update.py deleted file mode 100644 index c3600ab37..000000000 --- a/backend/api/migrations/0063_documents_permission_update.py +++ /dev/null @@ -1,48 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_compliance_period_permission(apps, schema_editor): - """ - Adds the View Compliance Period permission to FSDoc and FSDocSubmit roles - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - permission = apps.get_model('api', 'Permission') - - compliance_period_permission = permission.objects.get(code='VIEW_COMPLIANCE_PERIODS') - - role_permissions = [] - - roles = role.objects.using(db_alias).filter(name__in=[ - "FSDoc", "FSDocSubmit" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=compliance_period_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0062_auto_20190115_1640') - ] - - operations = [ - RunPython(add_compliance_period_permission, - None) - ] diff --git a/backend/api/migrations/0064_new_document_statuses.py b/backend/api/migrations/0064_new_document_statuses.py deleted file mode 100644 index b058b4115..000000000 --- a/backend/api/migrations/0064_new_document_statuses.py +++ /dev/null @@ -1,40 +0,0 @@ -from datetime import datetime - -from django.db import migrations, IntegrityError -from django.db.migrations import RunPython - - -def add_new_document_statuses(apps, schema_editor): - """Add additional document statuses""" - - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately versioned - # for this migration (so this shouldn't ever need to be maintained if fields change) - doc_status = apps.get_model("api", "DocumentStatus") - - doc_statuses = [ - doc_status(status='Security Scan Failed', - display_order=4, - effective_date='2017-01-01'), - doc_status(status='Pending Submission', - display_order=5, - effective_date='2017-01-01'), - ] - - for new_doc_status in doc_statuses: - if not doc_status.objects.using(db_alias).filter(status=new_doc_status.status).exists(): - doc_status.objects.using(db_alias).bulk_create([new_doc_status]) - else: - print('skipping existing document status {}'.format(new_doc_status.status)) - - -class Migration(migrations.Migration): - dependencies = [ - ('api', '0063_documents_permission_update'), - ] - - operations = [ - # This is a one-way trip - RunPython(add_new_document_statuses, reverse_code=None) - ] diff --git a/backend/api/migrations/0065_auto_20190114_2347.py b/backend/api/migrations/0065_auto_20190114_2347.py deleted file mode 100644 index 8f4d0c460..000000000 --- a/backend/api/migrations/0065_auto_20190114_2347.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-01-14 23:47 -from __future__ import unicode_literals - -import api.notifications.notification_types -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0064_new_document_statuses'), - ] - - operations = [ - migrations.AlterField( - model_name='notificationsubscription', - name='notification_type', - field=models.CharField(choices=[(api.notifications.notification_types.NotificationType('Credit Transfer Proposal Created'), 'Credit Transfer Proposal Created'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 1/2'), 'Credit Transfer Proposal Signed 1/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 2/2'), 'Credit Transfer Proposal Signed 2/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Refused'), 'Credit Transfer Proposal Refused'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Accepted'), 'Credit Transfer Proposal Accepted'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Approval'), 'Credit Transfer Proposal Recommended For Approval'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Declination'), 'Credit Transfer Proposal Recommended For Declination'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Declined'), 'Credit Transfer Proposal Declined'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Approved'), 'Credit Transfer Proposal Approved'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Rescinded'), 'Credit Transfer Proposal Rescinded'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Comment Created Or Updated'), 'Credit Transfer Proposal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Internal Comment Created Or Updated'), 'Credit Transfer Proposal Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Created'), 'PVR Created'), (api.notifications.notification_types.NotificationType('PVR Recommended For Approval'), 'PVR Recommended For Approval'), (api.notifications.notification_types.NotificationType('PVR Rescinded'), 'PVR Rescinded'), (api.notifications.notification_types.NotificationType('PVR Pulled Back'), 'PVR Pulled Back'), (api.notifications.notification_types.NotificationType('PVR Declined'), 'PVR Declined'), (api.notifications.notification_types.NotificationType('PVR Approved'), 'PVR Approved'), (api.notifications.notification_types.NotificationType('PVR Comment Created Or Updated'), 'PVR Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Internal Comment Created Or Updated'), 'PVR Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Returned to Analyst'), 'PVR Returned to Analyst'), (api.notifications.notification_types.NotificationType('Document Pending Submission'), 'Document Pending Submission'), (api.notifications.notification_types.NotificationType('Document Submitted'), 'Document Submitted'), (api.notifications.notification_types.NotificationType('Document Security Scan Failed'), 'Document Security Scan Failed')], max_length=128), - ), - ] diff --git a/backend/api/migrations/0066_documentfileattachment_is_removed.py b/backend/api/migrations/0066_documentfileattachment_is_removed.py deleted file mode 100644 index 52402f1eb..000000000 --- a/backend/api/migrations/0066_documentfileattachment_is_removed.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2019-01-16 19:40 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0065_auto_20190114_2347'), - ] - - operations = [ - migrations.AddField( - model_name='documentfileattachment', - name='is_removed', - field=models.BooleanField(default=False), - ), - ] diff --git a/backend/api/migrations/0067_permissions_remove_view_compliance_periods.py b/backend/api/migrations/0067_permissions_remove_view_compliance_periods.py deleted file mode 100644 index f181698c4..000000000 --- a/backend/api/migrations/0067_permissions_remove_view_compliance_periods.py +++ /dev/null @@ -1,80 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def remove_view_compliance_permission(apps, schema_editor): - """ - Removes the View Compliance Permission and the relationship - to the roles that uses it. - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - view_compliance_permission = permission.objects.using(db_alias).filter( - code="VIEW_COMPLIANCE_PERIODS" - ).first() - - if view_compliance_permission: - role_permission.objects.filter( - permission_id=view_compliance_permission.id - ).delete() - - view_compliance_permission.delete() - - -def add_view_compliance_permission(apps, schema_editor): - """ - Re-adds the View Compliance Period and the relationship to the roles - that previously had it. - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - view_compliance_permission = permission.objects.using(db_alias).create( - code="VIEW_COMPLIANCE_PERIODS", - name="View Compliance Periods", - description="Gives the user access to view compliance periods." - ) - - role_permissions = [] - - roles = role.objects.using(db_alias).filter(name__in=[ - "Admin", "FSAdmin", "FSDoc", "FSDocSubmit", "FSManager", "FSUser", - "GovDeputyDirector", "GovDirector", "GovUser" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=view_compliance_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0066_documentfileattachment_is_removed'), - ] - - operations = [ - RunPython(remove_view_compliance_permission, - add_view_compliance_permission) - ] diff --git a/backend/api/migrations/0068_rename_fuel_supply_records.py b/backend/api/migrations/0068_rename_fuel_supply_records.py deleted file mode 100644 index 6c5bb2103..000000000 --- a/backend/api/migrations/0068_rename_fuel_supply_records.py +++ /dev/null @@ -1,54 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def rename_to_compliance_reporting_materials(apps, schema_editor): - """ - Renames document type: Fuel Supply Records to Compliance - Reporting Materials - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_type = apps.get_model('api', 'DocumentType') - - document_type.objects.using(db_alias).filter( - the_type="Records" - ).update( - description="Compliance Reporting Materials" - ) - - -def revert_to_fuel_supply_records(apps, schema_editor): - """ - Renames transaction type: Compliance Reporting Materials to Fuel Supply - Records - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_type = apps.get_model('api', 'DocumentType') - - document_type.objects.using(db_alias).filter( - the_type="Records" - ).update( - description="Fuel Supply Records" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0067_permissions_remove_view_compliance_periods'), - ] - - operations = [ - RunPython(rename_to_compliance_reporting_materials, - revert_to_fuel_supply_records) - ] diff --git a/backend/api/migrations/0069_remove_documenthistory_user_role.py b/backend/api/migrations/0069_remove_documenthistory_user_role.py deleted file mode 100644 index 101d02bd5..000000000 --- a/backend/api/migrations/0069_remove_documenthistory_user_role.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2019-01-21 17:22 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0068_rename_fuel_supply_records'), - ] - - operations = [ - migrations.RemoveField( - model_name='documenthistory', - name='user_role' - ), - ] diff --git a/backend/api/migrations/0070_rename_credit_retirement.py b/backend/api/migrations/0070_rename_credit_retirement.py deleted file mode 100644 index 9da68606c..000000000 --- a/backend/api/migrations/0070_rename_credit_retirement.py +++ /dev/null @@ -1,52 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def rename_to_credit_reduction(apps, schema_editor): - """ - Renames transaction type: Credit Retirement to Credit Reduction - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - credit_trade_type = apps.get_model('api', 'CreditTradeType') - - credit_trade_type.objects.using(db_alias).filter( - the_type="Credit Retirement" - ).update( - the_type="Credit Reduction" - ) - - -def revert_to_credit_retirement(apps, schema_editor): - """ - Renames transaction type: Credit Reduction back to Credit Retirement - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - credit_trade_type = apps.get_model('api', 'CreditTradeType') - - credit_trade_type.objects.using(db_alias).filter( - the_type="Credit Reduction" - ).update( - the_type="Credit Retirement" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0069_remove_documenthistory_user_role'), - ] - - operations = [ - RunPython(rename_to_credit_reduction, - revert_to_credit_retirement) - ] diff --git a/backend/api/migrations/0071_rename_document_upload.py b/backend/api/migrations/0071_rename_document_upload.py deleted file mode 100644 index 725071919..000000000 --- a/backend/api/migrations/0071_rename_document_upload.py +++ /dev/null @@ -1,141 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def rename_to_file_submission(apps, schema_editor): - """ - Renames references of document upload to file submission - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - permission = apps.get_model('api', 'Permission') - - role.objects.using(db_alias).filter( - name="FSDoc" - ).update( - description="File Submission (Government)" - ) - - role.objects.using(db_alias).filter( - name="FSDocSubmit" - ).update( - description="File Submission" - ) - - role_permission.objects.using(db_alias).filter( - permission__code="DOCUMENTS_CREATE_DRAFT", - role__name="FSDoc" - ).delete() - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_CREATE_DRAFT" - ).update( - name="Upload files into a draft state", - description="Securely upload files and save as a draft (not visible " - "to Government)." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_GOVERNMENT_REVIEW" - ).update( - name="Review file submissions", - description="The ability to review file submissions (mark them as " - "reviewed status)." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_SUBMIT" - ).update( - name="File Submissions", - description="Securely upload and submit file." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_VIEW" - ).update( - name="View file submissions", - description="View and download file submissions that have been " - "securely uploaded." - ) - - -def revert_to_document_upload(apps, schema_editor): - """ - Renames file submission references back to document upload - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - permission = apps.get_model('api', 'Permission') - - role.objects.using(db_alias).filter( - name="FSDoc" - ).update( - description="Document Upload (Government)" - ) - - role.objects.using(db_alias).filter( - name="FSDocSubmit" - ).update( - description="Document Upload" - ) - - role_permission.objects.using(db_alias).create( - permission=permission.objects.using(db_alias).get( - code="DOCUMENTS_CREATE_DRAFT"), - role=role.objects.using(db_alias).get(name="FSDoc") - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_CREATE_DRAFT" - ).update( - name="Upload documents into a draft state", - description="Securely upload documents and save as a draft (not " - "visible to Government)." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_GOVERNMENT_REVIEW" - ).update( - name="Review uploaded documents", - description="The ability to review uploaded documents (mark them as " - "reviewed status)." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_SUBMIT" - ).update( - name="Upload documents", - description="Securely upload and submit documents." - ) - - permission.objects.using(db_alias).filter( - code="DOCUMENTS_VIEW" - ).update( - name="View uploaded documents", - description="View and download documents that have been securely " - "uploaded." - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0070_rename_credit_retirement'), - ] - - operations = [ - RunPython(rename_to_file_submission, - revert_to_document_upload) - ] diff --git a/backend/api/migrations/0072_notificationmessage_related_document.py b/backend/api/migrations/0072_notificationmessage_related_document.py deleted file mode 100644 index e693abc00..000000000 --- a/backend/api/migrations/0072_notificationmessage_related_document.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2019-01-22 21:26 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0071_rename_document_upload'), - ] - - operations = [ - migrations.AddField( - model_name='notificationmessage', - name='related_document', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='api.Document'), - ), - ] diff --git a/backend/api/migrations/0073_auto_20190128_2014.py b/backend/api/migrations/0073_auto_20190128_2014.py deleted file mode 100644 index c54d3e29d..000000000 --- a/backend/api/migrations/0073_auto_20190128_2014.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2019-01-28 20:14 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0072_notificationmessage_related_document'), - ] - - operations = [ - migrations.AlterField( - model_name='documentfileattachment', - name='document', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='document_attachments', to='api.Document'), - ), - ] diff --git a/backend/api/migrations/0074_add_document_statuses.py b/backend/api/migrations/0074_add_document_statuses.py deleted file mode 100644 index b792a0544..000000000 --- a/backend/api/migrations/0074_add_document_statuses.py +++ /dev/null @@ -1,55 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_document_statuses(apps, schema_editor): - """ - Adds Cancelled and Rescinded statuses to DocumentStatus - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_status = apps.get_model('api', 'DocumentStatus') - document_status.objects.using(db_alias).bulk_create([ - document_status( - status="Rescinded", - effective_date="2017-01-01", - display_order="6" - ), - document_status( - status="Cancelled", - effective_date="2017-01-01", - display_order="7" - ) - ]) - - -def remove_document_statuses(apps, schema_editor): - """ - Re-adds the View Compliance Period and the relationship to the roles - that previously had it. - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_status = apps.get_model('api', 'DocumentStatus') - document_status.objects.using(db_alias).filter( - status__in=["Cancelled", "Rescinded"]).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0073_auto_20190128_2014'), - ] - - operations = [ - RunPython(add_document_statuses, - remove_document_statuses) - ] diff --git a/backend/api/migrations/0075_remove_document_rescinded_status.py b/backend/api/migrations/0075_remove_document_rescinded_status.py deleted file mode 100644 index 30c8e6ac2..000000000 --- a/backend/api/migrations/0075_remove_document_rescinded_status.py +++ /dev/null @@ -1,48 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def remove_document_status(apps, schema_editor): - """ - Re-adds the View Compliance Period and the relationship to the roles - that previously had it. - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_status = apps.get_model('api', 'DocumentStatus') - document_status.objects.using(db_alias).filter( - status="Rescinded").delete() - - -def add_document_status(apps, schema_editor): - """ - Adds Cancelled and Rescinded statuses to DocumentStatus - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_status = apps.get_model('api', 'DocumentStatus') - document_status.objects.using(db_alias).create( - status="Rescinded", - effective_date="2017-01-01", - display_order="6" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0074_add_document_statuses'), - ] - - operations = [ - RunPython(remove_document_status, - add_document_status) - ] diff --git a/backend/api/migrations/0076_add_document_status_archived.py b/backend/api/migrations/0076_add_document_status_archived.py deleted file mode 100644 index e9f719ff4..000000000 --- a/backend/api/migrations/0076_add_document_status_archived.py +++ /dev/null @@ -1,47 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_document_status(apps, schema_editor): - """ - Adds Archived status - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_status = apps.get_model('api', 'DocumentStatus') - document_status.objects.using(db_alias).create( - status="Archived", - effective_date="2017-01-01", - display_order="8" - ) - - -def remove_document_status(apps, schema_editor): - """ - Removes the Archived status - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - document_status = apps.get_model('api', 'DocumentStatus') - document_status.objects.using(db_alias).filter( - status="Archived").delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0075_remove_document_rescinded_status'), - ] - - operations = [ - RunPython(add_document_status, - remove_document_status) - ] diff --git a/backend/api/migrations/0077_auto_20190211_1930.py b/backend/api/migrations/0077_auto_20190211_1930.py deleted file mode 100644 index a8c601d2c..000000000 --- a/backend/api/migrations/0077_auto_20190211_1930.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-11 19:30 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0076_add_document_status_archived'), - ] - - operations = [ - migrations.RemoveField( - model_name='document', - name='record_number', - ), - migrations.RemoveField( - model_name='documenthistory', - name='record_number', - ), - migrations.AddField( - model_name='documentfileattachment', - name='record_number', - field=models.CharField(blank=True, max_length=100, null=True), - ), - ] diff --git a/backend/api/migrations/0078_auto_20190211_2127.py b/backend/api/migrations/0078_auto_20190211_2127.py deleted file mode 100644 index 0f8b80187..000000000 --- a/backend/api/migrations/0078_auto_20190211_2127.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-11 21:27 -from __future__ import unicode_literals - -import api.notifications.notification_types -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0077_auto_20190211_1930'), - ] - - operations = [ - migrations.AlterField( - model_name='notificationsubscription', - name='notification_type', - field=models.CharField(choices=[(api.notifications.notification_types.NotificationType('Credit Transfer Proposal Created'), 'Credit Transfer Proposal Created'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 1/2'), 'Credit Transfer Proposal Signed 1/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 2/2'), 'Credit Transfer Proposal Signed 2/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Refused'), 'Credit Transfer Proposal Refused'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Accepted'), 'Credit Transfer Proposal Accepted'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Approval'), 'Credit Transfer Proposal Recommended For Approval'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Declination'), 'Credit Transfer Proposal Recommended For Declination'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Declined'), 'Credit Transfer Proposal Declined'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Approved'), 'Credit Transfer Proposal Approved'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Rescinded'), 'Credit Transfer Proposal Rescinded'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Comment Created Or Updated'), 'Credit Transfer Proposal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Internal Comment Created Or Updated'), 'Credit Transfer Proposal Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Created'), 'PVR Created'), (api.notifications.notification_types.NotificationType('PVR Recommended For Approval'), 'PVR Recommended For Approval'), (api.notifications.notification_types.NotificationType('PVR Rescinded'), 'PVR Rescinded'), (api.notifications.notification_types.NotificationType('PVR Pulled Back'), 'PVR Pulled Back'), (api.notifications.notification_types.NotificationType('PVR Declined'), 'PVR Declined'), (api.notifications.notification_types.NotificationType('PVR Approved'), 'PVR Approved'), (api.notifications.notification_types.NotificationType('PVR Comment Created Or Updated'), 'PVR Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Internal Comment Created Or Updated'), 'PVR Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Returned to Analyst'), 'PVR Returned to Analyst'), (api.notifications.notification_types.NotificationType('Document Pending Submission'), 'Document Pending Submission'), (api.notifications.notification_types.NotificationType('Document Submitted'), 'Document Submitted'), (api.notifications.notification_types.NotificationType('Document Security Scan Failed'), 'Document Security Scan Failed'), (api.notifications.notification_types.NotificationType('Document Received'), 'Document Received'), (api.notifications.notification_types.NotificationType('Document Archived'), 'Document Archived')], max_length=128), - ), - ] diff --git a/backend/api/migrations/0079_auto_20190219_1859.py b/backend/api/migrations/0079_auto_20190219_1859.py deleted file mode 100644 index 52ddb451a..000000000 --- a/backend/api/migrations/0079_auto_20190219_1859.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-19 18:59 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0078_auto_20190211_2127'), - ] - - operations = [ - migrations.RemoveField( - model_name='credittradehistory', - name='is_internal_history_record', - ), - migrations.RemoveField( - model_name='credittradehistory', - name='note', - ), - migrations.RemoveField( - model_name='credittradehistory', - name='update_timestamp', - ), - migrations.RemoveField( - model_name='credittradehistory', - name='update_user', - ), - ] diff --git a/backend/api/migrations/0080_remove_credittrade_note.py b/backend/api/migrations/0080_remove_credittrade_note.py deleted file mode 100644 index 225e3fca1..000000000 --- a/backend/api/migrations/0080_remove_credittrade_note.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-19 20:02 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0079_auto_20190219_1859'), - ] - - operations = [ - migrations.RemoveField( - model_name='credittrade', - name='note', - ), - ] diff --git a/backend/api/migrations/0081_auto_20190220_0014.py b/backend/api/migrations/0081_auto_20190220_0014.py deleted file mode 100644 index 4b45e3279..000000000 --- a/backend/api/migrations/0081_auto_20190220_0014.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-20 00:14 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0080_remove_credittrade_note'), - ] - - operations = [ - migrations.CreateModel( - name='DocumentCreditTrade', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentcredittrade_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('credit_trade', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.CreditTrade')), - ('document', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.Document')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_documentcredittrade_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'document_credit_trade', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AddField( - model_name='credittrade', - name='documents', - field=models.ManyToManyField(through='api.DocumentCreditTrade', to='api.Document'), - ), - migrations.AddField( - model_name='document', - name='credit_trades', - field=models.ManyToManyField(through='api.DocumentCreditTrade', to='api.CreditTrade'), - ), - migrations.AlterUniqueTogether( - name='documentcredittrade', - unique_together=set([('credit_trade', 'document')]), - ), - ] diff --git a/backend/api/migrations/0082_document_link_permissions.py b/backend/api/migrations/0082_document_link_permissions.py deleted file mode 100644 index bbe603f1e..000000000 --- a/backend/api/migrations/0082_document_link_permissions.py +++ /dev/null @@ -1,67 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def remove_document_link_permission(apps, schema_editor): - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - link_permission = permission.objects.using(db_alias).filter( - code="DOCUMENTS_LINK_TO_CREDIT_TRADE" - ).first() - - if link_permission: - role_permission.objects.filter( - permission_id=link_permission.id - ).delete() - - link_permission.delete() - - -def add_document_link_permission(apps, schema_editor): - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - link_permission = permission.objects.using(db_alias).create( - code="DOCUMENTS_LINK_TO_CREDIT_TRADE", - name="Establish links between credit transactions and secure file submissions", - description="Gives the user access to modify document links." - ) - - role_permissions = [] - - roles = role.objects.using(db_alias).filter(name__in=[ - "GovDeputyDirector", "GovDirector", "GovUser" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=link_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0081_auto_20190220_0014'), - ] - - operations = [ - RunPython( - add_document_link_permission, - remove_document_link_permission - ) - ] diff --git a/backend/api/migrations/0083_fuelcode.py b/backend/api/migrations/0083_fuelcode.py deleted file mode 100644 index 6bd76d8f2..000000000 --- a/backend/api/migrations/0083_fuelcode.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-11-21 16:52 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0082_document_link_permissions'), - ] - - operations = [ - migrations.CreateModel( - name='FuelCode', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('fuel_code', models.CharField(max_length=100)), - ('company', models.CharField(max_length=100)), - ('carbon_intensity', models.DecimalField(blank=True, decimal_places=2, default=None, max_digits=999, null=True)), - ('application_date', models.DateField(blank=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiry_date', models.DateField(blank=True, null=True)), - ('fuel', models.CharField(blank=True, max_length=100, null=True)), - ('feedstock', models.CharField(blank=True, max_length=100, null=True)), - ('feedstock_location', models.CharField(blank=True, max_length=100, null=True)), - ('feedstock_misc', models.CharField(blank=True, max_length=100, null=True)), - ('facility_location', models.CharField(blank=True, max_length=100, null=True)), - ('facility_nameplate', models.IntegerField(blank=True, null=True)), - ('feedstock_transport_mode', models.CharField(blank=True, max_length=100, null=True)), - ('fuel_transport_mode', models.CharField(blank=True, max_length=100, null=True)), - ('former_company', models.CharField(blank=True, max_length=100, null=True)), - ('approval_date', models.DateField(blank=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fuelcode_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fuelcode_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'fuel_code', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0084_fuelcodestatus.py b/backend/api/migrations/0084_fuelcodestatus.py deleted file mode 100644 index 68878b1b6..000000000 --- a/backend/api/migrations/0084_fuelcodestatus.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-21 23:51 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0083_fuelcode'), - ] - - operations = [ - migrations.CreateModel( - name='FuelCodeStatus', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('status', models.CharField(blank=True, max_length=25, null=True, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fuelcodestatus_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fuelcodestatus_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'fuel_code_status', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0085_add_fuel_code_statuses.py b/backend/api/migrations/0085_add_fuel_code_statuses.py deleted file mode 100644 index e237b8071..000000000 --- a/backend/api/migrations/0085_add_fuel_code_statuses.py +++ /dev/null @@ -1,54 +0,0 @@ -from datetime import datetime - -from django.db import migrations -from django.db.migrations import RunPython - - -def add_fuel_code_statuses(apps, schema_editor): - """Add basic fuel code statuses""" - - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - fuel_code_status = apps.get_model('api', 'FuelCodeStatus') - fuel_code_status.objects.using(db_alias).bulk_create([ - fuel_code_status( - status='Draft', - display_order=1 - ), - fuel_code_status( - status='Submitted', - display_order=2 - ), - fuel_code_status( - status='Cancelled', - display_order=3 - ) - ]) - - -def remove_fuel_code_statuses(apps, schema_editor): - """ - Re-adds the View Compliance Period and the relationship to the roles - that previously had it. - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - fuel_code_status = apps.get_model('api', 'FuelCodeStatus') - fuel_code_status.objects.using(db_alias).filter( - status__in=["Draft", "Submitted", "Cancelled"]).delete() - - -class Migration(migrations.Migration): - dependencies = [ - ('api', '0084_fuelcodestatus'), - ] - - operations = [ - RunPython(add_fuel_code_statuses, remove_fuel_code_statuses) - ] diff --git a/backend/api/migrations/0086_fuelcode_status.py b/backend/api/migrations/0086_fuelcode_status.py deleted file mode 100644 index 0db9d4fa9..000000000 --- a/backend/api/migrations/0086_fuelcode_status.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-22 00:02 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0085_add_fuel_code_statuses'), - ] - - operations = [ - migrations.AddField( - model_name='fuelcode', - name='status', - field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.PROTECT, to='api.FuelCodeStatus'), - preserve_default=False, - ), - ] diff --git a/backend/api/migrations/0087_add_fuel_code_permissions.py b/backend/api/migrations/0087_add_fuel_code_permissions.py deleted file mode 100644 index 6de0fbf25..000000000 --- a/backend/api/migrations/0087_add_fuel_code_permissions.py +++ /dev/null @@ -1,110 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_fuel_code_permissions(apps, schema_editor): - """ - Creates the basic permissions for the roles to manage and view - fuel codes - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - view_permission = permission.objects.using(db_alias).create( - code="FUEL_CODES_VIEW", - name="View Fuel Codes", - description="The ability to access and view Fuel Codes." - ) - - manage_permission = permission.objects.using(db_alias).create( - code="FUEL_CODES_MANAGE", - name="Edit Fuel Codes", - description="The ability to create and update Fuel Codes." - ) - - role_permissions = [] - - roles = role_model.objects.using(db_alias).filter(name__in=[ - "GovDeputyDirector", "GovDirector", "GovUser" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=view_permission - ) - ) - - role_permissions.append( - role_permission( - role=role, - permission=manage_permission - ) - ) - - roles = role_model.objects.using(db_alias).filter(name__in=[ - "FSAdmin", "FSManager", "FSUser" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=view_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_fuel_code_permissions(apps, schema_editor): - """ - Removes the fuel code permissions from roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - manage_permission = permission.objects.using(db_alias).filter( - code="FUEL_CODES_MANAGE" - ).first() - - if manage_permission: - role_permission.objects.filter( - permission_id=manage_permission.id - ).delete() - - manage_permission.delete() - - view_permission = permission.objects.using(db_alias).filter( - code="FUEL_CODES_VIEW" - ).first() - - if view_permission: - role_permission.objects.filter( - permission_id=view_permission.id - ).delete() - - view_permission.delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0086_fuelcode_status'), - ] - - operations = [ - RunPython( - add_fuel_code_permissions, - remove_fuel_code_permissions - ) - ] diff --git a/backend/api/migrations/0088_auto_20190228_1911.py b/backend/api/migrations/0088_auto_20190228_1911.py deleted file mode 100644 index 0f3d0216d..000000000 --- a/backend/api/migrations/0088_auto_20190228_1911.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-28 19:11 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0087_add_fuel_code_permissions'), - ] - - operations = [ - migrations.AlterField( - model_name='fuelcode', - name='carbon_intensity', - field=models.DecimalField(blank=True, decimal_places=2, default=None, max_digits=5, null=True), - ), - ] diff --git a/backend/api/migrations/0089_auto_20190228_2106.py b/backend/api/migrations/0089_auto_20190228_2106.py deleted file mode 100644 index 78ffd1ebd..000000000 --- a/backend/api/migrations/0089_auto_20190228_2106.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-02-28 21:06 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0088_auto_20190228_1911'), - ] - - operations = [ - migrations.AddField( - model_name='fuelcodestatus', - name='effective_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='fuelcodestatus', - name='expiration_date', - field=models.DateField(blank=True, null=True), - ), - ] diff --git a/backend/api/migrations/0090_fuel_code_status_set_effective_dates.py b/backend/api/migrations/0090_fuel_code_status_set_effective_dates.py deleted file mode 100644 index 788aa19db..000000000 --- a/backend/api/migrations/0090_fuel_code_status_set_effective_dates.py +++ /dev/null @@ -1,44 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_fuel_code_status_effective_dates(apps, schema_editor): - """ - Adds the effective dates for fuel code status - """ - db_alias = schema_editor.connection.alias - - fuel_code_status = apps.get_model('api', 'FuelCodeStatus') - - fuel_code_status.objects.using(db_alias).update( - effective_date="2017-01-01" - ) - - -def remove_fuel_code_status_effective_dates(apps, schema_editor): - """ - Removes the effective dates from fuel code status - """ - db_alias = schema_editor.connection.alias - - fuel_code_status = apps.get_model('api', 'FuelCodeStatus') - - fuel_code_status.objects.using(db_alias).update( - effective_date=None - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0089_auto_20190228_2106'), - ] - - operations = [ - RunPython( - update_fuel_code_status_effective_dates, - remove_fuel_code_status_effective_dates - ) - ] diff --git a/backend/api/migrations/0091_rename_fsdoc_role.py b/backend/api/migrations/0091_rename_fsdoc_role.py deleted file mode 100644 index fc5a67a25..000000000 --- a/backend/api/migrations/0091_rename_fsdoc_role.py +++ /dev/null @@ -1,46 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def rename_fsdoc_role(apps, schema_editor): - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', 'Role') - - fsdoc_role = role.objects.using(db_alias).filter( - name="FSDoc" - ).first() - - fsdoc_role.name = 'GovDoc' - - fsdoc_role.save() - - -def revert_rename_fsdoc_role(apps, schema_editor): - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', 'Role') - - fsdoc_role = role.objects.using(db_alias).filter( - name="GovDoc" - ).first() - - fsdoc_role.name = 'FSDoc' - - fsdoc_role.save() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0090_fuel_code_status_set_effective_dates'), - ] - - operations = [ - RunPython( - rename_fsdoc_role, - revert_rename_fsdoc_role, - ) - ] diff --git a/backend/api/migrations/0092_auto_20190305_0417.py b/backend/api/migrations/0092_auto_20190305_0417.py deleted file mode 100644 index e5a785d3f..000000000 --- a/backend/api/migrations/0092_auto_20190305_0417.py +++ /dev/null @@ -1,131 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-03-05 04:17 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0091_rename_fsdoc_role'), - ] - - operations = [ - migrations.CreateModel( - name='ApprovedFuel', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('name', models.CharField(max_length=100, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_approvedfuel_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_approvedfuel_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'approved_fuel', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='FeedstockTransportMode', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_feedstocktransportmode_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'feedstock_transport_mode_fuel_code', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='FuelTransportMode', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fueltransportmode_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'fuel_transport_mode_fuel_code', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='TransportMode', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('name', models.CharField(max_length=100, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_transportmode_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_transportmode_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'fuel_transport_mode', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.RemoveField( - model_name='fuelcode', - name='feedstock_transport_mode', - ), - migrations.AlterField( - model_name='fuelcode', - name='fuel', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel'), - ), - migrations.RemoveField( - model_name='fuelcode', - name='fuel_transport_mode', - ), - migrations.AddField( - model_name='fueltransportmode', - name='fuel_code', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.FuelCode'), - ), - migrations.AddField( - model_name='fueltransportmode', - name='transport_mode', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.TransportMode'), - ), - migrations.AddField( - model_name='fueltransportmode', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fueltransportmode_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='feedstocktransportmode', - name='fuel_code', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.FuelCode'), - ), - migrations.AddField( - model_name='feedstocktransportmode', - name='transport_mode', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.TransportMode'), - ), - migrations.AddField( - model_name='feedstocktransportmode', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_feedstocktransportmode_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='fuelcode', - name='feedstock_transport_mode', - field=models.ManyToManyField(related_name='_fuelcode_feedstock_transport_mode_+', through='api.FeedstockTransportMode', to='api.TransportMode'), - ), - migrations.AddField( - model_name='fuelcode', - name='fuel_transport_mode', - field=models.ManyToManyField(related_name='_fuelcode_fuel_transport_mode_+', through='api.FuelTransportMode', to='api.TransportMode'), - ), - ] diff --git a/backend/api/migrations/0093_initial_transport_modes_and_approved_fuels.py b/backend/api/migrations/0093_initial_transport_modes_and_approved_fuels.py deleted file mode 100644 index 4c6429f78..000000000 --- a/backend/api/migrations/0093_initial_transport_modes_and_approved_fuels.py +++ /dev/null @@ -1,91 +0,0 @@ -from __future__ import unicode_literals - -from django.db.migrations import RunPython - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - -approved_fuel_names = [ - 'Biodiesel', - 'CNG', - 'Electricity', - 'Ethanol', - 'HDRD', - 'Hydrogen', - 'LNG', - 'Propane', - 'Renewable diesel', - 'Renewable gasoline' -] - - -def add_transport_modes_and_approved_fuels(apps, schema_editor): - """Add initial transport modes and approved fuels""" - - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - transport_mode = apps.get_model('api', 'TransportMode') - transport_mode.objects.using(db_alias).bulk_create([ - transport_mode( - name='Truck', - effective_date='2017-01-01' - ), - transport_mode( - name='Rail', - effective_date='2017-01-01' - ), - transport_mode( - name='Marine', - effective_date='2017-01-01' - ), - transport_mode( - name='Adjacent', - effective_date='2017-01-01' - ), - transport_mode( - name='Pipeline', - effective_date='2017-01-01' - ) - ]) - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - approved_fuel.objects.using(db_alias).bulk_create( - map(lambda af: approved_fuel( - name=af, - effective_date='2017-01-01' - ), approved_fuel_names) - ) - - -def remove_transport_modes_and_approved_fuels(apps, schema_editor): - """ - Remove initial transport modes and approved fuels - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - transport_mode = apps.get_model('api', 'TransportMode') - transport_mode.objects.using(db_alias).filter( - name__in=["Truck", "Rail", "Marine", "Adjacent", "Pipeline"]).delete() - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - approved_fuel.objects.using(db_alias).filter( - name__in=approved_fuel_names).delete() - - -class Migration(migrations.Migration): - dependencies = [ - ('api', '0092_auto_20190305_0417'), - ] - - operations = [ - RunPython(add_transport_modes_and_approved_fuels, - remove_transport_modes_and_approved_fuels) - ] diff --git a/backend/api/migrations/0094_auto_20190305_2356.py b/backend/api/migrations/0094_auto_20190305_2356.py deleted file mode 100644 index 82633f49d..000000000 --- a/backend/api/migrations/0094_auto_20190305_2356.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-03-05 23:56 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0093_initial_transport_modes_and_approved_fuels'), - ] - - operations = [ - migrations.AlterModelTable( - name='approvedfuel', - table='approved_fuel_type', - ), - migrations.AlterModelTable( - name='transportmode', - table='fuel_transport_mode_type', - ), - ] diff --git a/backend/api/migrations/0095_auto_20190301_1659.py b/backend/api/migrations/0095_auto_20190301_1659.py deleted file mode 100644 index aa9c1c36a..000000000 --- a/backend/api/migrations/0095_auto_20190301_1659.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.18 on 2019-03-01 16:59 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0094_auto_20190305_2356'), - ] - - operations = [ - migrations.AddField( - model_name='usercreationrequest', - name='external_username', - field=models.CharField(blank=True, max_length=150, null=True), - ), - migrations.AlterField( - model_name='usercreationrequest', - name='keycloak_email', - field=models.EmailField(max_length=254), - ), - migrations.AlterUniqueTogether( - name='usercreationrequest', - unique_together=set([('keycloak_email', 'external_username')]), - ), - ] diff --git a/backend/api/migrations/0096_add_trgm_extension.py b/backend/api/migrations/0096_add_trgm_extension.py deleted file mode 100644 index d7aecdd72..000000000 --- a/backend/api/migrations/0096_add_trgm_extension.py +++ /dev/null @@ -1,27 +0,0 @@ -from django.db import migrations, connection -from django.db.migrations import RunPython - - -def add_trgrm_extension(apps, schema_editor): - """ - Add the postgresql trigram matching extension - """ - if schema_editor.connection.vendor == 'postgresql': - with schema_editor.connection.cursor() as cursor: - cursor.execute("create extension if not exists pg_trgm") - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0095_auto_20190301_1659'), - ] - - operations = [ - RunPython( - add_trgrm_extension, - reverse_code=None - ) - ] diff --git a/backend/api/migrations/0097_add_autocomplete_indices.py b/backend/api/migrations/0097_add_autocomplete_indices.py deleted file mode 100644 index 65e99c8c1..000000000 --- a/backend/api/migrations/0097_add_autocomplete_indices.py +++ /dev/null @@ -1,49 +0,0 @@ -from collections import namedtuple - -from django.db import migrations, connection -from django.db.migrations import RunPython - - -def add_autocomplete_indices(apps, schema_editor): - """ - Add the postgresql indices for faster autocompletion - """ - if schema_editor.connection.vendor != 'postgresql': - return - - Index = namedtuple('Index', [ - 'index_name', - 'table', - 'column' - ]) - - indices = [ - Index('idx_autocomplete_company', 'fuel_code', 'company'), - Index('idx_autocomplete_former_company', 'fuel_code', 'former_company'), - Index('idx_autocomplete_feedstock', 'fuel_code', 'feedstock'), - Index('idx_autocomplete_feedstock_location', 'fuel_code', 'feedstock_location'), - Index('idx_autocomplete_feedstock_misc', 'fuel_code', 'feedstock_misc') - ] - - with schema_editor.connection.cursor() as cursor: - for index in indices: - cursor.execute("create index {index_name} on {table} USING GIST ({column} gist_trgm_ops)" - .format(table=index.table, - column=index.column, - index_name=index.index_name)) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0096_add_trgm_extension'), - ] - - operations = [ - RunPython( - add_autocomplete_indices, - reverse_code=None - ) - ] diff --git a/backend/api/migrations/0098_rename_fuel_status_submitted.py b/backend/api/migrations/0098_rename_fuel_status_submitted.py deleted file mode 100644 index 37c74ca26..000000000 --- a/backend/api/migrations/0098_rename_fuel_status_submitted.py +++ /dev/null @@ -1,46 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def rename_submitted_status(apps, schema_editor): - db_alias = schema_editor.connection.alias - - status = apps.get_model('api', 'FuelCodeStatus') - - submitted_status = status.objects.using(db_alias).filter( - status="Submitted" - ).first() - - if submitted_status: - submitted_status.status = 'Approved' - submitted_status.save() - - -def revert_submitted_status(apps, schema_editor): - db_alias = schema_editor.connection.alias - - status = apps.get_model('api', 'FuelCodeStatus') - - approved_status = status.objects.using(db_alias).filter( - status="Approved" - ).first() - - if approved_status: - approved_status.status = 'Submitted' - approved_status.save() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0097_add_autocomplete_indices'), - ] - - operations = [ - RunPython( - rename_submitted_status, - revert_submitted_status, - ) - ] diff --git a/backend/api/migrations/0099_add_approved_fuel.py b/backend/api/migrations/0099_add_approved_fuel.py deleted file mode 100644 index 300b5e1eb..000000000 --- a/backend/api/migrations/0099_add_approved_fuel.py +++ /dev/null @@ -1,46 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_natural_gas_based_gasoline(apps, schema_editor): - """ - Add natural gas based gasoline into Approved Fuel - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - approved_fuel = apps.get_model('api', 'ApprovedFuel') - approved_fuel.objects.using(db_alias).create( - name="Natural gas-based gasoline", - effective_date="2017-01-01" - ) - - -def remove_natural_gas_based_gasoline(apps, schema_editor): - """ - Removes natural gas based gasoline from Approved Fuel - """ - db_alias = schema_editor.connection.alias - - # By retrieving the models via apps.get_model, we get one appropriately - # versioned for this migration (so this shouldn't ever need to be - # maintained if fields change) - approved_fuel = apps.get_model('api', 'ApprovedFuel') - approved_fuel.objects.using(db_alias).filter( - name="Natural gas-based gasoline" - ).delete() - - -class Migration(migrations.Migration): - dependencies = [ - ('api', '0098_rename_fuel_status_submitted'), - ] - - operations = [ - RunPython( - add_natural_gas_based_gasoline, - remove_natural_gas_based_gasoline - ) - ] diff --git a/backend/api/migrations/0100_auto_20190329_1942.py b/backend/api/migrations/0100_auto_20190329_1942.py deleted file mode 100644 index 773a2b89e..000000000 --- a/backend/api/migrations/0100_auto_20190329_1942.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-03-29 19:42 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0099_add_approved_fuel'), - ] - - operations = [ - migrations.AlterField( - model_name='user', - name='cell_phone', - field=models.CharField(blank=True, max_length=50, null=True), - ), - migrations.AlterField( - model_name='user', - name='phone', - field=models.CharField(blank=True, max_length=50, null=True), - ), - ] diff --git a/backend/api/migrations/0101_auto_20190329_2115.py b/backend/api/migrations/0101_auto_20190329_2115.py deleted file mode 100644 index 141d47624..000000000 --- a/backend/api/migrations/0101_auto_20190329_2115.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-03-29 21:15 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0100_auto_20190329_1942'), - ] - - operations = [ - migrations.AddField( - model_name='fuelcode', - name='fuel_code_version', - field=models.IntegerField(default=100), - preserve_default=False, - ), - migrations.AddField( - model_name='fuelcode', - name='fuel_code_version_minor', - field=models.IntegerField(blank=True, null=True), - ), - migrations.AlterField( - model_name='fuelcode', - name='fuel_code', - field=models.CharField(default='BCLCF', max_length=10), - ), - ] diff --git a/backend/api/migrations/0102_auto_20190401_2109.py b/backend/api/migrations/0102_auto_20190401_2109.py deleted file mode 100644 index 3b34539a2..000000000 --- a/backend/api/migrations/0102_auto_20190401_2109.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-01 21:09 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0101_auto_20190329_2115'), - ] - - operations = [ - migrations.AlterField( - model_name='fuelcode', - name='fuel_code_version_minor', - field=models.IntegerField(default=0), - ), - migrations.AlterUniqueTogether( - name='fuelcode', - unique_together=set([('fuel_code', 'fuel_code_version', 'fuel_code_version_minor')]), - ), - ] diff --git a/backend/api/migrations/0103_auto_20190402_2318.py b/backend/api/migrations/0103_auto_20190402_2318.py deleted file mode 100644 index 817e1c506..000000000 --- a/backend/api/migrations/0103_auto_20190402_2318.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-02 23:18 -from __future__ import unicode_literals - -import api.validators -from decimal import Decimal -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0102_auto_20190401_2109'), - ] - - operations = [ - migrations.AlterField( - model_name='credittrade', - name='fair_market_value_per_credit', - field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=10, null=True, validators=[api.validators.CreditTradeFairMarketValueValidator]), - ), - ] diff --git a/backend/api/migrations/0104_auto_20190403_1616.py b/backend/api/migrations/0104_auto_20190403_1616.py deleted file mode 100644 index 18bd0fc87..000000000 --- a/backend/api/migrations/0104_auto_20190403_1616.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-03 16:16 -from __future__ import unicode_literals - -import db_comments.model_mixins -from decimal import Decimal -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0103_auto_20190402_2318'), - ] - - operations = [ - migrations.CreateModel( - name='CarbonIntensityLimit', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('density', models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=5, null=True)), - ('compliance_period', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='carbon_intensity_limits', to='api.CompliancePeriod')), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_carbonintensitylimit_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'carbon_intensity_limit', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='FuelClass', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('fuel_class', models.CharField(max_length=50, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fuelclass_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_fuelclass_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'fuel_class', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AddField( - model_name='carbonintensitylimit', - name='fuel_class', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='carbon_intensity_limits', to='api.FuelClass'), - ), - migrations.AddField( - model_name='carbonintensitylimit', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_carbonintensitylimit_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0105_add_credit_calculation_permissions.py b/backend/api/migrations/0105_add_credit_calculation_permissions.py deleted file mode 100644 index 0a3a6d82c..000000000 --- a/backend/api/migrations/0105_add_credit_calculation_permissions.py +++ /dev/null @@ -1,111 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_credit_calculation_permissions(apps, schema_editor): - """ - Creates the basic permissions for the roles to manage and view - credit calculation related tables - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - view_permission = permission.objects.using(db_alias).create( - code="CREDIT_CALCULATION_VIEW", - name="View Credit Calculation Limits", - description="The ability to access and view credit calculation limits." - ) - - manage_permission = permission.objects.using(db_alias).create( - code="CREDIT_CALCULATION_MANAGE", - name="Edit Credit Calculation Limits", - description="The ability to create and update credit calculation " - "limits." - ) - - role_permissions = [] - - roles = role_model.objects.using(db_alias).filter(name__in=[ - "GovDeputyDirector", "GovDirector", "GovUser" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=view_permission - ) - ) - - role_permissions.append( - role_permission( - role=role, - permission=manage_permission - ) - ) - - roles = role_model.objects.using(db_alias).filter(name__in=[ - "FSAdmin", "FSManager", "FSUser" - ]) - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=view_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_credit_calculation_permissions(apps, schema_editor): - """ - Removes the credit calculation permissions from roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - manage_permission = permission.objects.using(db_alias).filter( - code="CREDIT_CALCULATION_MANAGE" - ).first() - - if manage_permission: - role_permission.objects.filter( - permission_id=manage_permission.id - ).delete() - - manage_permission.delete() - - view_permission = permission.objects.using(db_alias).filter( - code="CREDIT_CALCULATION_VIEW" - ).first() - - if view_permission: - role_permission.objects.filter( - permission_id=view_permission.id - ).delete() - - view_permission.delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0104_auto_20190403_1616'), - ] - - operations = [ - RunPython( - add_credit_calculation_permissions, - remove_credit_calculation_permissions - ) - ] diff --git a/backend/api/migrations/0106_add_fuel_classes.py b/backend/api/migrations/0106_add_fuel_classes.py deleted file mode 100644 index fa2a7aec7..000000000 --- a/backend/api/migrations/0106_add_fuel_classes.py +++ /dev/null @@ -1,51 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_fuel_classes(apps, schema_editor): - """ - Creates the fuel classes: Gasoline and Diesel - """ - db_alias = schema_editor.connection.alias - - fuel_class = apps.get_model('api', 'FuelClass') - - fuel_class.objects.using(db_alias).bulk_create([ - fuel_class( - fuel_class="Diesel", - display_order=1, - effective_date='2017-01-01' - ), - fuel_class( - fuel_class="Gasoline", - display_order=2, - effective_date='2017-01-01' - ) - ]) - - -def remove_fuel_classes(apps, schema_editor): - """ - Removes the credit calculation permissions from roles - """ - db_alias = schema_editor.connection.alias - - fuel_class = apps.get_model('api', 'FuelClass') - - fuel_class.objects.using(db_alias).all().delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0105_add_credit_calculation_permissions'), - ] - - operations = [ - RunPython( - add_fuel_classes, - remove_fuel_classes - ) - ] diff --git a/backend/api/migrations/0107_auto_20190404_1942.py b/backend/api/migrations/0107_auto_20190404_1942.py deleted file mode 100644 index 0601ada76..000000000 --- a/backend/api/migrations/0107_auto_20190404_1942.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-04 19:42 -from __future__ import unicode_literals - -import db_comments.model_mixins -from decimal import Decimal -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0106_add_fuel_classes'), - ] - - operations = [ - migrations.CreateModel( - name='EnergyEffectivenessRatio', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('ratio', models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=5, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energyeffectivenessratio_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'energy_effectiveness_ratio', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AddField( - model_name='approvedfuel', - name='credit_calculation_only', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='energyeffectivenessratio', - name='fuel', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='energy_effective_ratio', to='api.ApprovedFuel'), - ), - migrations.AddField( - model_name='energyeffectivenessratio', - name='fuel_class', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='energy_effective_ratio', to='api.FuelClass'), - ), - migrations.AddField( - model_name='energyeffectivenessratio', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energyeffectivenessratio_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0108_auto_20190408_2311.py b/backend/api/migrations/0108_auto_20190408_2311.py deleted file mode 100644 index a5075448d..000000000 --- a/backend/api/migrations/0108_auto_20190408_2311.py +++ /dev/null @@ -1,81 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-08 23:11 -from __future__ import unicode_literals - -import db_comments.model_mixins -from decimal import Decimal -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0107_auto_20190404_1942'), - ] - - operations = [ - migrations.CreateModel( - name='DefaultCarbonIntensity', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('density', models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=5, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_defaultcarbonintensity_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('fuel', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='default_carbon_intensity', to='api.ApprovedFuel')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_defaultcarbonintensity_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'default_carbon_intensity', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='EnergyDensity', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('density', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energydensity_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('fuel', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='energy_density', to='api.ApprovedFuel')), - ], - options={ - 'db_table': 'energy_density', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='UnitOfMeasure', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('name', models.CharField(max_length=50)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_unitofmeasure_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_unitofmeasure_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'unit_of_measure', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AddField( - model_name='energydensity', - name='unit_of_measure', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='energy_density', to='api.UnitOfMeasure'), - ), - migrations.AddField( - model_name='energydensity', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energydensity_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0109_auto_20190409_2101.py b/backend/api/migrations/0109_auto_20190409_2101.py deleted file mode 100644 index 0ea0dca2c..000000000 --- a/backend/api/migrations/0109_auto_20190409_2101.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-09 21:01 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0108_auto_20190408_2311'), - ] - - operations = [ - migrations.AlterField( - model_name='approvedfuel', - name='name', - field=models.CharField(max_length=255, unique=True), - ), - ] diff --git a/backend/api/migrations/0110_add_credit_calculation_fuel_types.py b/backend/api/migrations/0110_add_credit_calculation_fuel_types.py deleted file mode 100644 index 15ea0fb1e..000000000 --- a/backend/api/migrations/0110_add_credit_calculation_fuel_types.py +++ /dev/null @@ -1,82 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_credit_calculation_fuel_types(apps, schema_editor): - """ - Adds additional fuel types for credit calculation - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).bulk_create([ - approved_fuel( - name='Petroleum-based diesel fuel or renewable fuel in relation ' - 'to diesel class fuel', - effective_date='2017-01-01', - credit_calculation_only=True - ), - approved_fuel( - name='Petroleum-based gasoline, natural gas-based gasoline or ' - 'renewable fuel in relation to gasoline class fuel', - effective_date='2017-01-01', - credit_calculation_only=True - ), - approved_fuel( - name='Petroleum-based diesel fuel or diesel fuel produced from ' - 'biomass', - effective_date='2017-01-01', - credit_calculation_only=True - ), - approved_fuel( - name='Petroleum-based gasoline, natural gas-based gasoline or ' - 'gasoline produced from biomass', - effective_date='2017-01-01', - credit_calculation_only=True - ), - approved_fuel( - name='Hydrogenation-derived renewable diesel fuel', - effective_date='2017-01-01', - credit_calculation_only=True - ), - approved_fuel( - name='Renewable fuel in relation to diesel class fuel', - effective_date='2017-01-01', - credit_calculation_only=True - ), - approved_fuel( - name='Renewable fuel in relation to gasoline class fuel', - effective_date='2017-01-01', - credit_calculation_only=True - ) - ]) - - -def remove_credit_calculation_fuel_types(apps, schema_editor): - """ - Removes the credit calculation fuel types - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).filter( - credit_calculation_only=True - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0109_auto_20190409_2101'), - ] - - operations = [ - RunPython( - add_credit_calculation_fuel_types, - remove_credit_calculation_fuel_types - ) - ] diff --git a/backend/api/migrations/0111_update_credit_calculation_fuel_types.py b/backend/api/migrations/0111_update_credit_calculation_fuel_types.py deleted file mode 100644 index 24853d7c4..000000000 --- a/backend/api/migrations/0111_update_credit_calculation_fuel_types.py +++ /dev/null @@ -1,97 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_credit_calculation_fuel_types(apps, schema_editor): - """ - Removes the fuel types that will be moved into its own categories - Adds some fuel types - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).filter( - credit_calculation_only=True - ).delete() - - approved_fuel.objects.using(db_alias).bulk_create([ - approved_fuel( - name="Petroleum-based diesel", - effective_date="2017-01-01", - credit_calculation_only=True - ), - approved_fuel( - name="Petroleum-based gasoline", - effective_date="2017-01-01", - credit_calculation_only=True - ) - ]) - - -def remove_credit_calculation_fuel_types(apps, schema_editor): - """ - Re-adds the fuel types that were removed - Removes the additional fuel types that were generated by this migration - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).bulk_create([ - approved_fuel( - name="Petroleum-based diesel fuel or renewable fuel in relation " - "to diesel class fuel", - effective_date="2017-01-01", - credit_calculation_only=True - ), - approved_fuel( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "renewable fuel in relation to gasoline class fuel", - effective_date="2017-01-01", - credit_calculation_only=True - ), - approved_fuel( - name="Petroleum-based diesel fuel or diesel fuel produced from " - "biomass", - effective_date="2017-01-01", - credit_calculation_only=True - ), - approved_fuel( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "gasoline produced from biomass", - effective_date="2017-01-01", - credit_calculation_only=True - ), - approved_fuel( - name="Hydrogenation-derived renewable diesel fuel", - effective_date="2017-01-01", - credit_calculation_only=True - ), - approved_fuel( - name="Renewable fuel in relation to diesel class fuel", - effective_date="2017-01-01", - credit_calculation_only=True - ), - approved_fuel( - name="Renewable fuel in relation to gasoline class fuel", - effective_date="2017-01-01", - credit_calculation_only=True - ) - ]) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0110_add_credit_calculation_fuel_types'), - ] - - operations = [ - RunPython( - add_credit_calculation_fuel_types, - remove_credit_calculation_fuel_types - ) - ] diff --git a/backend/api/migrations/0112_auto_20190411_1530.py b/backend/api/migrations/0112_auto_20190411_1530.py deleted file mode 100644 index fa34838be..000000000 --- a/backend/api/migrations/0112_auto_20190411_1530.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-11 15:30 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0111_update_credit_calculation_fuel_types'), - ] - - operations = [ - migrations.RemoveField( - model_name='energydensity', - name='unit_of_measure', - ), - migrations.AlterField( - model_name='approvedfuel', - name='name', - field=models.CharField(max_length=100, unique=True), - ), - ] diff --git a/backend/api/migrations/0113_auto_20190411_1551.py b/backend/api/migrations/0113_auto_20190411_1551.py deleted file mode 100644 index 6d93c906a..000000000 --- a/backend/api/migrations/0113_auto_20190411_1551.py +++ /dev/null @@ -1,96 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-11 15:51 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0112_auto_20190411_1530'), - ] - - operations = [ - migrations.CreateModel( - name='DefaultCarbonIntensityCategory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('name', models.CharField(blank=True, max_length=255, null=True, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_defaultcarbonintensitycategory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_defaultcarbonintensitycategory_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'default_carbon_intensity_category', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='EnergyDensityCategory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('name', models.CharField(blank=True, max_length=255, null=True, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energydensitycategory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energydensitycategory_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'energy_density_category', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='EnergyEffectivenessRatioCategory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('name', models.CharField(blank=True, max_length=255, null=True, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energyeffectivenessratiocategory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_energyeffectivenessratiocategory_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'energy_effectiveness_ratio_category', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.RemoveField( - model_name='defaultcarbonintensity', - name='fuel', - ), - migrations.RemoveField( - model_name='energydensity', - name='fuel', - ), - migrations.RemoveField( - model_name='energyeffectivenessratio', - name='fuel', - ), - migrations.AddField( - model_name='defaultcarbonintensity', - name='category', - field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.PROTECT, related_name='default_carbon_intensity', to='api.DefaultCarbonIntensityCategory'), - preserve_default=False, - ), - migrations.AddField( - model_name='energydensity', - name='category', - field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.PROTECT, related_name='energy_density', to='api.EnergyDensityCategory'), - preserve_default=False, - ), - migrations.AddField( - model_name='energyeffectivenessratio', - name='category', - field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.PROTECT, related_name='energy_effective_ratio', to='api.EnergyEffectivenessRatioCategory'), - preserve_default=False, - ), - ] diff --git a/backend/api/migrations/0114_add_categories.py b/backend/api/migrations/0114_add_categories.py deleted file mode 100644 index 446e2cd65..000000000 --- a/backend/api/migrations/0114_add_categories.py +++ /dev/null @@ -1,168 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_categories(apps, schema_editor): - """ - Adds additional fuel types for credit calculation - """ - db_alias = schema_editor.connection.alias - - category = apps.get_model('api', 'DefaultCarbonIntensityCategory') - - category.objects.using(db_alias).bulk_create([ - category( - name="CNG", - display_order=1 - ), - category( - name="Electricity", - display_order=2 - ), - category( - name="Hydrogen", - display_order=3 - ), - category( - name="LNG", - display_order=4 - ), - category( - name="Natural gas-based gasoline", - display_order=5 - ), - category( - name="Petroleum-based diesel", - display_order=6 - ), - category( - name="Petroleum-based gasoline", - display_order=7 - ), - category( - name="Propane", - display_order=8 - ), - category( - name="Renewable Fuel in relation to diesel class fuel", - display_order=9 - ), - category( - name="Renewable Fuel in relation to gasoline class fuel", - display_order=10 - ) - ]) - - category = apps.get_model('api', 'EnergyDensityCategory') - - category.objects.using(db_alias).bulk_create([ - category( - name="Biodiesel", - display_order=1 - ), - category( - name="CNG", - display_order=2 - ), - category( - name="Electricity", - display_order=3 - ), - category( - name="Ethanol", - display_order=4 - ), - category( - name="Hydrogenation-derived renewable diesel fuel", - display_order=5 - ), - category( - name="Hydrogen", - display_order=6 - ), - category( - name="LNG", - display_order=7 - ), - category( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "gasoline produced from biomass", - display_order=8 - ), - category( - name="Petroleum-based diesel fuel or diesel fuel produced from " - "biomass", - display_order=9 - ), - category( - name="Propane", - display_order=10 - ) - ]) - - category = apps.get_model('api', 'EnergyEffectivenessRatioCategory') - - category.objects.using(db_alias).bulk_create([ - category( - name="CNG", - display_order=1 - ), - category( - name="Electricity", - display_order=2 - ), - category( - name="Hydrogen", - display_order=3 - ), - category( - name="LNG", - display_order=4 - ), - category( - name="Petroleum-based diesel fuel or renewable fuel in relation " - "to diesel class fuel", - display_order=5 - ), - category( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "renewable fuel in relation to gasoline class fuel", - display_order=6 - ), - category( - name="Propane", - display_order=7 - ) - ]) - - -def remove_categories(apps, schema_editor): - """ - Removes the credit calculation fuel types - """ - db_alias = schema_editor.connection.alias - - category = apps.get_model('api', 'DefaultCarbonIntensityCategory') - category.objects.using(db_alias).delete() - - category = apps.get_model('api', 'EnergyDensityCategory') - category.objects.using(db_alias).delete() - - category = apps.get_model('api', 'EnergyEffectivenessRatioCategory') - category.objects.using(db_alias).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0113_auto_20190411_1551'), - ] - - operations = [ - RunPython( - add_categories, - remove_categories - ) - ] diff --git a/backend/api/migrations/0115_auto_20190411_1615.py b/backend/api/migrations/0115_auto_20190411_1615.py deleted file mode 100644 index 44a5315b0..000000000 --- a/backend/api/migrations/0115_auto_20190411_1615.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-11 16:15 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0114_add_categories'), - ] - - operations = [ - migrations.AddField( - model_name='approvedfuel', - name='default_carbon_intensity_category', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_fuel', to='api.DefaultCarbonIntensityCategory'), - ), - migrations.AddField( - model_name='approvedfuel', - name='energy_density_category', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_fuel', to='api.EnergyDensityCategory'), - ), - migrations.AddField( - model_name='approvedfuel', - name='energy_effectiveness_ratio_category', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_fuel', to='api.EnergyEffectivenessRatioCategory'), - ), - migrations.AddField( - model_name='approvedfuel', - name='unit_of_measure', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='approved_fuel', to='api.UnitOfMeasure'), - ), - ] diff --git a/backend/api/migrations/0116_add_categories_to_approved_fuel.py b/backend/api/migrations/0116_add_categories_to_approved_fuel.py deleted file mode 100644 index ee2e60842..000000000 --- a/backend/api/migrations/0116_add_categories_to_approved_fuel.py +++ /dev/null @@ -1,281 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_categories(apps, schema_editor): - """ - Adds additional fuel types for credit calculation - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - default_carbon_intensity_category = apps.get_model( - 'api', 'DefaultCarbonIntensityCategory') - energy_density_category = apps.get_model( - 'api', 'EnergyDensityCategory') - energy_effectiveness_ratio_category = apps.get_model( - 'api', 'EnergyEffectivenessRatioCategory') - - approved_fuel.objects.using(db_alias).filter( - name="Biodiesel" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Renewable Fuel in relation to diesel class fuel" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Biodiesel" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based diesel fuel or renewable fuel in relation " - "to diesel class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="CNG" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="CNG" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="CNG" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="CNG" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Electricity" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Electricity" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Electricity" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Electricity" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Ethanol" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Renewable Fuel in relation to gasoline class fuel" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Ethanol" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "renewable fuel in relation to gasoline class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="HDRD" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Renewable Fuel in relation to diesel class fuel" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Hydrogenation-derived renewable diesel fuel" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based diesel fuel or renewable fuel in relation " - "to diesel class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Hydrogen" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Hydrogen" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Hydrogen" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Hydrogen" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="LNG" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="LNG" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="LNG" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="LNG" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Natural gas-based gasoline" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Natural gas-based gasoline" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "gasoline produced from biomass" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "renewable fuel in relation to gasoline class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Petroleum-based diesel" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Petroleum-based diesel" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Petroleum-based diesel fuel or diesel fuel produced from " - "biomass" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based diesel fuel or renewable fuel in relation " - "to diesel class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Petroleum-based gasoline" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "gasoline produced from biomass" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "renewable fuel in relation to gasoline class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Propane" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Propane" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Propane" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Propane" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Renewable diesel" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Petroleum-based diesel" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Petroleum-based diesel fuel or diesel fuel produced from " - "biomass" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based diesel fuel or renewable fuel in relation " - "to diesel class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Renewable gasoline" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline" - ), - energy_density_category=energy_density_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "gasoline produced from biomass" - ), - energy_effectiveness_ratio_category=energy_effectiveness_ratio_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline, natural gas-based gasoline or " - "renewable fuel in relation to gasoline class fuel" - ) - ) - - -def remove_categories(apps, schema_editor): - """ - Removes the credit calculation fuel types - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - approved_fuel.objects.using(db_alias).update( - default_carbon_intensity_category=None, - energy_density_category=None, - energy_effectiveness_ratio_category=None - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0115_auto_20190411_1615'), - ] - - operations = [ - RunPython( - add_categories, - remove_categories - ) - ] diff --git a/backend/api/migrations/0117_add_unit_of_measures.py b/backend/api/migrations/0117_add_unit_of_measures.py deleted file mode 100644 index 24227f77a..000000000 --- a/backend/api/migrations/0117_add_unit_of_measures.py +++ /dev/null @@ -1,88 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_unit_of_measures(apps, schema_editor): - """ - Adds additional fuel types for credit calculation - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - unit_of_measure = apps.get_model('api', 'UnitOfMeasure') - - uom_l = unit_of_measure.objects.using(db_alias).create( - name="L", - effective_date="2017-01-01" - ) - uom_kg = unit_of_measure.objects.using(db_alias).create( - name="kg", - effective_date="2017-01-01" - ) - uom_kwh = unit_of_measure.objects.using(db_alias).create( - name="kWh", - effective_date="2017-01-01" - ) - uom_m3 = unit_of_measure.objects.using(db_alias).create( - name="m³", - effective_date="2017-01-01" - ) - - approved_fuel.objects.using(db_alias).filter( - name__in=[ - "Biodiesel", "Ethanol", "HDRD", "Natural gas-based gasoline", - "Petroleum-based diesel", "Petroleum-based gasoline", - "Propane", "Renewable diesel", "Renewable gasoline" - ] - ).update( - unit_of_measure=uom_l - ) - approved_fuel.objects.using(db_alias).filter( - name__in=[ - "Hydrogen", "LNG" - ] - ).update( - unit_of_measure=uom_kg - ) - approved_fuel.objects.using(db_alias).filter( - name="Electricity" - ).update( - unit_of_measure=uom_kwh - ) - approved_fuel.objects.using(db_alias).filter( - name="CNG" - ).update( - unit_of_measure=uom_m3 - ) - - -def remove_unit_of_measures(apps, schema_editor): - """ - Removes the credit calculation fuel types - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - unit_of_measure = apps.get_model('api', 'UnitOfMeasure') - - approved_fuel.objects.using(db_alias).update( - unit_of_measure=None - ) - - unit_of_measure.objects.using(db_alias).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0116_add_categories_to_approved_fuel'), - ] - - operations = [ - RunPython( - add_unit_of_measures, - remove_unit_of_measures - ) - ] diff --git a/backend/api/migrations/0118_approvedfuel_description.py b/backend/api/migrations/0118_approvedfuel_description.py deleted file mode 100644 index 217236536..000000000 --- a/backend/api/migrations/0118_approvedfuel_description.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-12 21:10 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0117_add_unit_of_measures'), - ] - - operations = [ - migrations.AddField( - model_name='approvedfuel', - name='description', - field=models.CharField(blank=True, max_length=1000, null=True), - ), - ] diff --git a/backend/api/migrations/0119_add_approved_fuel_descriptions.py b/backend/api/migrations/0119_add_approved_fuel_descriptions.py deleted file mode 100644 index 162371508..000000000 --- a/backend/api/migrations/0119_add_approved_fuel_descriptions.py +++ /dev/null @@ -1,86 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_descriptions(apps, schema_editor): - """ - Adds Fuel Descriptions - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).filter( - name="Biodiesel" - ).update( - description="Biodiesel fuel" - ) - approved_fuel.objects.using(db_alias).filter( - name="CNG" - ).update( - description="Compressed natural gas" - ) - approved_fuel.objects.using(db_alias).filter( - name="Ethanol" - ).update( - description="Ethanol produced from biomass" - ) - approved_fuel.objects.using(db_alias).filter( - name="HDRD" - ).update( - description="Hydrogenation-derived renewable diesel fuel" - ) - approved_fuel.objects.using(db_alias).filter( - name="LNG" - ).update( - description="Liquefied natural gas" - ) - approved_fuel.objects.using(db_alias).filter( - name="Petroleum-based diesel" - ).update( - description="Diesel fuel, diesel, petroleum-based diesel" - ) - approved_fuel.objects.using(db_alias).filter( - name="Petroleum-based gasoline" - ).update( - description="Gasoline" - ) - approved_fuel.objects.using(db_alias).filter( - name="Renewable diesel" - ).update( - description="Diesel fuel produced from biomass" - ) - approved_fuel.objects.using(db_alias).filter( - name="Renewable gasoline" - ).update( - description="Gasoline produced from biomass" - ) - - -def remove_descriptions(apps, schema_editor): - """ - Removes the descriptions from fuels - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).update( - description=None - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0118_approvedfuel_description'), - ] - - operations = [ - RunPython( - add_descriptions, - remove_descriptions - ) - ] diff --git a/backend/api/migrations/0120_approvedfuelclass.py b/backend/api/migrations/0120_approvedfuelclass.py deleted file mode 100644 index 3daa76451..000000000 --- a/backend/api/migrations/0120_approvedfuelclass.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-12 22:59 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0119_add_approved_fuel_descriptions'), - ] - - operations = [ - migrations.CreateModel( - name='ApprovedFuelClass', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_approvedfuelclass_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('fuel', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='approved_fuel_class', to='api.ApprovedFuel')), - ('fuel_class', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='approved_fuel_class', to='api.FuelClass')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_approvedfuelclass_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'approved_fuel_class', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0121_add_fuel_class_relationships.py b/backend/api/migrations/0121_add_fuel_class_relationships.py deleted file mode 100644 index 8ed5a1047..000000000 --- a/backend/api/migrations/0121_add_fuel_class_relationships.py +++ /dev/null @@ -1,89 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_fuel_class_relationships(apps, schema_editor): - """ - Adds Fuel Descriptions - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - approved_fuel_class = apps.get_model('api', 'ApprovedFuelClass') - fuel_class = apps.get_model('api', 'FuelClass') - - diesel_fuels = approved_fuel.objects.using(db_alias).filter( - name__in=[ - "Biodiesel", "CNG", "Electricity", "HDRD", "Hydrogen", "LNG", - "Petroleum-based diesel", "Propane", "Renewable diesel" - ] - ) - - diesel_fuel_classes = [] - - for fuel in diesel_fuels: - diesel_fuel_classes.append( - approved_fuel_class( - fuel=approved_fuel.objects.using(db_alias).get( - name=fuel.name - ), - fuel_class=fuel_class.objects.using(db_alias).get( - fuel_class="Diesel" - ) - ) - ) - - approved_fuel_class.objects.using(db_alias).bulk_create( - diesel_fuel_classes) - - gasoline_fuels = approved_fuel.objects.using(db_alias).filter( - name__in=[ - "CNG", "Electricity", "Ethanol", "Hydrogen", - "Natural gas-based gasoline", "Petroleum-based gasoline", - "Propane", "Renewable gasoline" - ] - ) - - gasoline_fuel_classes = [] - - for fuel in gasoline_fuels: - gasoline_fuel_classes.append( - approved_fuel_class( - fuel=approved_fuel.objects.using(db_alias).get( - name=fuel.name - ), - fuel_class=fuel_class.objects.using(db_alias).get( - fuel_class="Gasoline" - ) - ) - ) - - approved_fuel_class.objects.using(db_alias).bulk_create( - gasoline_fuel_classes) - - -def remove_fuel_class_relationships(apps, schema_editor): - """ - Removes the descriptions from fuels - """ - db_alias = schema_editor.connection.alias - - approved_fuel_class = apps.get_model('api', 'ApprovedFuelClass') - - approved_fuel_class.objects.using(db_alias).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0120_approvedfuelclass'), - ] - - operations = [ - RunPython( - add_fuel_class_relationships, - remove_fuel_class_relationships - ) - ] diff --git a/backend/api/migrations/0122_auto_20190425_1514.py b/backend/api/migrations/0122_auto_20190425_1514.py deleted file mode 100644 index d30c28d8d..000000000 --- a/backend/api/migrations/0122_auto_20190425_1514.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-25 15:14 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0121_add_fuel_class_relationships'), - ] - - operations = [ - migrations.AddField( - model_name='defaultcarbonintensitycategory', - name='effective_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='defaultcarbonintensitycategory', - name='expiration_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='energydensitycategory', - name='effective_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='energydensitycategory', - name='expiration_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='energyeffectivenessratiocategory', - name='effective_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='energyeffectivenessratiocategory', - name='expiration_date', - field=models.DateField(blank=True, null=True), - ), - ] diff --git a/backend/api/migrations/0123_auto_20190424_1639.py b/backend/api/migrations/0123_auto_20190424_1639.py deleted file mode 100644 index a8b00efa6..000000000 --- a/backend/api/migrations/0123_auto_20190424_1639.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-04-24 16:39 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0122_auto_20190425_1514'), - ] - - operations = [ - migrations.AddField( - model_name='approvedfuel', - name='is_partially_renewable', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='fuelcode', - name='renewable_percentage', - field=models.DecimalField(blank=True, decimal_places=2, default=None, max_digits=5, null=True), - ), - ] diff --git a/backend/api/migrations/0124_update_partially_renewable_fuels.py b/backend/api/migrations/0124_update_partially_renewable_fuels.py deleted file mode 100644 index 61daf3699..000000000 --- a/backend/api/migrations/0124_update_partially_renewable_fuels.py +++ /dev/null @@ -1,54 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_partially_renewable_fuel_types(apps, schema_editor): - """ - Marks some fuel types as partially renewable - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).filter( - name__in=[ - "Biodiesel", "Ethanol", "HDRD", "Natural gas-based gasoline", - "Renewable diesel", "Renewable gasoline" - ] - ).update( - is_partially_renewable=True - ) - - -def remove_partially_renewable_fuel_types(apps, schema_editor): - """ - Sets all fuel types to not be partially renewable - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - - approved_fuel.objects.using(db_alias).filter( - name__in=[ - "Biodiesel", "Ethanol", "HDRD", "Natural gas-based gasoline", - "Renewable diesel", "Renewable gasoline" - ] - ).update( - is_partially_renewable=False - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0123_auto_20190424_1639'), - ] - - operations = [ - RunPython( - update_partially_renewable_fuel_types, - remove_partially_renewable_fuel_types - ) - ] diff --git a/backend/api/migrations/0125_lowercase_renewable_fuel.py b/backend/api/migrations/0125_lowercase_renewable_fuel.py deleted file mode 100644 index 2a26540b0..000000000 --- a/backend/api/migrations/0125_lowercase_renewable_fuel.py +++ /dev/null @@ -1,60 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_to_lowercase(apps, schema_editor): - """ - Sets fuel to lowercase in Renewable Fuel in relation to ... - """ - db_alias = schema_editor.connection.alias - - category = apps.get_model('api', 'DefaultCarbonIntensityCategory') - - category.objects.using(db_alias).filter( - name="Renewable Fuel in relation to diesel class fuel" - ).update( - name="Renewable fuel in relation to diesel class fuel" - ) - - category.objects.using(db_alias).filter( - name="Renewable Fuel in relation to gasoline class fuel" - ).update( - name="Renewable fuel in relation to gasoline class fuel" - ) - - -def update_to_uppercase(apps, schema_editor): - """ - Sets fuel to uppercase in Renewable fuel in relation to ... - """ - db_alias = schema_editor.connection.alias - - category = apps.get_model('api', 'DefaultCarbonIntensityCategory') - - category.objects.using(db_alias).filter( - name="Renewable fuel in relation to diesel class fuel" - ).update( - name="Renewable Fuel in relation to diesel class fuel" - ) - - category.objects.using(db_alias).filter( - name="Renewable fuel in relation to gasoline class fuel" - ).update( - name="Renewable Fuel in relation to gasoline class fuel" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0124_update_partially_renewable_fuels'), - ] - - operations = [ - RunPython( - update_to_lowercase, - update_to_uppercase - ) - ] diff --git a/backend/api/migrations/0126_auto_20190502_2024.py b/backend/api/migrations/0126_auto_20190502_2024.py deleted file mode 100644 index 56316991f..000000000 --- a/backend/api/migrations/0126_auto_20190502_2024.py +++ /dev/null @@ -1,67 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-02 20:24 -from __future__ import unicode_literals - -import db_comments.model_mixins -from decimal import Decimal -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0125_lowercase_renewable_fuel'), - ] - - operations = [ - migrations.CreateModel( - name='PetroleumCarbonIntensity', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('density', models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=5, null=True)), - ], - options={ - 'db_table': 'petroleum_carbon_intensity', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='PetroleumCarbonIntensityCategory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('name', models.CharField(blank=True, max_length=255, null=True, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_petroleumcarbonintensitycategory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_petroleumcarbonintensitycategory_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'petroleum_carbon_intensity_category', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AddField( - model_name='petroleumcarbonintensity', - name='category', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='petroleum_carbon_intensity', to='api.PetroleumCarbonIntensityCategory'), - ), - migrations.AddField( - model_name='petroleumcarbonintensity', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_petroleumcarbonintensity_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='petroleumcarbonintensity', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_petroleumcarbonintensity_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0127_add_petroleum_carbon_intensity_categories.py b/backend/api/migrations/0127_add_petroleum_carbon_intensity_categories.py deleted file mode 100644 index d36962487..000000000 --- a/backend/api/migrations/0127_add_petroleum_carbon_intensity_categories.py +++ /dev/null @@ -1,48 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_categories(apps, schema_editor): - """ - Adds petroleum-based diesel fuel and gasoline categories - """ - db_alias = schema_editor.connection.alias - - category = apps.get_model('api', 'PetroleumCarbonIntensityCategory') - - category.objects.using(db_alias).bulk_create([ - category( - name="Petroleum-based diesel", - display_order=1 - ), - category( - name="Petroleum-based gasoline", - display_order=2 - ) - ]) - - -def remove_categories(apps, schema_editor): - """ - Removes the petroleum-based categories - """ - db_alias = schema_editor.connection.alias - - category = apps.get_model('api', 'PetroleumCarbonIntensityCategory') - category.objects.using(db_alias).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0126_auto_20190502_2024'), - ] - - operations = [ - RunPython( - add_categories, - remove_categories - ) - ] diff --git a/backend/api/migrations/0128_clean_filenames.py b/backend/api/migrations/0128_clean_filenames.py deleted file mode 100644 index b00ec212f..000000000 --- a/backend/api/migrations/0128_clean_filenames.py +++ /dev/null @@ -1,35 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def clean_filenames(apps, schema_editor): - """ - Removes query strings from urls - """ - db_alias = schema_editor.connection.alias - - attachments = apps.get_model('api', 'DocumentFileAttachment') - - rows = attachments.objects.using(db_alias).filter( - url__contains="?" - ) - - for row in rows: - row.url = row.url.split('?')[0] - row.save() - - -class Migration(migrations.Migration): - """ - Remove query strings from all stored attachments - """ - dependencies = [ - ('api', '0127_add_petroleum_carbon_intensity_categories'), - ] - - operations = [ - RunPython( - clean_filenames, - None - ) - ] diff --git a/backend/api/migrations/0129_expecteduse.py b/backend/api/migrations/0129_expecteduse.py deleted file mode 100644 index 3d1d3c257..000000000 --- a/backend/api/migrations/0129_expecteduse.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-13 21:05 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0128_clean_filenames'), - ] - - operations = [ - migrations.CreateModel( - name='ExpectedUse', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('description', models.CharField(max_length=100, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_expecteduse_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_expecteduse_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'expected_use_type', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0130_auto_20190513_2144.py b/backend/api/migrations/0130_auto_20190513_2144.py deleted file mode 100644 index b2bdfed21..000000000 --- a/backend/api/migrations/0130_auto_20190513_2144.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-13 21:44 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0129_expecteduse'), - ] - - operations = [ - migrations.CreateModel( - name='AutosavedFormData', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('key', models.CharField(max_length=256, verbose_name='key')), - ('data', models.TextField(null=True, verbose_name='data')), - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'autosaved_form_data', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AlterUniqueTogether( - name='autosavedformdata', - unique_together=set([('user', 'key')]), - ), - ] diff --git a/backend/api/migrations/0131_autosavedformdata_last_access.py b/backend/api/migrations/0131_autosavedformdata_last_access.py deleted file mode 100644 index 01e42f3fb..000000000 --- a/backend/api/migrations/0131_autosavedformdata_last_access.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-14 17:42 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0130_auto_20190513_2144'), - ] - - operations = [ - migrations.AddField( - model_name='autosavedformdata', - name='last_access', - field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='last_access'), - ), - ] diff --git a/backend/api/migrations/0132_auto_20190522_1753.py b/backend/api/migrations/0132_auto_20190522_1753.py deleted file mode 100644 index 769920778..000000000 --- a/backend/api/migrations/0132_auto_20190522_1753.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-22 17:53 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0131_autosavedformdata_last_access'), - ] - - operations = [ - migrations.CreateModel( - name='ComplianceReport', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('compliance_period', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='api.CompliancePeriod')), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereport_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Organization')), - ], - options={ - 'db_table': 'compliance_report', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='ComplianceReportStatus', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('status', models.CharField(blank=True, max_length=25, null=True, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereportstatus_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereportstatus_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'compliance_report_status', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='ComplianceReportType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('display_order', models.IntegerField()), - ('the_type', models.CharField(max_length=100, unique=True)), - ('description', models.CharField(blank=True, max_length=1000)), - ], - options={ - 'db_table': 'compliance_report_type', - }, - ), - migrations.AddField( - model_name='compliancereport', - name='status', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ComplianceReportStatus'), - ), - migrations.AddField( - model_name='compliancereport', - name='type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ComplianceReportType'), - ), - migrations.AddField( - model_name='compliancereport', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereport_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0133_add_compliance_report_types_and_statuses.py b/backend/api/migrations/0133_add_compliance_report_types_and_statuses.py deleted file mode 100644 index 09bfb4b41..000000000 --- a/backend/api/migrations/0133_add_compliance_report_types_and_statuses.py +++ /dev/null @@ -1,70 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_compliance_report_types_and_statuses(apps, schema_editor): - """ - Adds Basic Compliance Report Types and Statuses - """ - db_alias = schema_editor.connection.alias - - compliance_report_type = apps.get_model('api', 'ComplianceReportType') - compliance_report_status = apps.get_model('api', 'ComplianceReportStatus') - - compliance_report_type.objects.using(db_alias).bulk_create([ - compliance_report_type( - the_type='Compliance Report', - description='Annual Compliance Report', - display_order=10 - ), - compliance_report_type( - the_type='Exclusion Report', - description='Annual Exclusion Report', - display_order=20 - ) - ]) - - compliance_report_status.objects.using(db_alias).bulk_create([ - compliance_report_status( - status='Draft', - display_order=10, - ), - compliance_report_status( - status='Submitted', - display_order=20, - ), - compliance_report_status( - status='Deleted', - display_order=5, - ) - ]) - - -def remove_compliance_report_types_and_statuses(apps, schema_editor): - """ - Removes Basic Compliance Report Types and Statuses - """ - db_alias = schema_editor.connection.alias - compliance_report_type = apps.get_model('api', 'ComplianceReportType') - compliance_report_status = apps.get_model('api', 'ComplianceReportStatus') - - compliance_report_type.objects.using(db_alias).get(the_type='Compliance Report').delete() - compliance_report_type.objects.using(db_alias).get(the_type='Exclusion Report').delete() - compliance_report_status.objects.using(db_alias).get(status='Draft').delete() - compliance_report_status.objects.using(db_alias).get(status='Submitted').delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0132_auto_20190522_1753'), - ] - - operations = [ - RunPython( - add_compliance_report_types_and_statuses, - remove_compliance_report_types_and_statuses - ) - ] diff --git a/backend/api/migrations/0134_add_compliance_reporting_roles.py b/backend/api/migrations/0134_add_compliance_reporting_roles.py deleted file mode 100644 index 2e3c8b02a..000000000 --- a/backend/api/migrations/0134_add_compliance_reporting_roles.py +++ /dev/null @@ -1,82 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_compliance_reporting_roles(apps, schema_editor): - """ - Creates the basic permissions for the roles to manage and view - credit calculation related tables - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - manage_permission = permission.objects.using(db_alias).create( - code="COMPLIANCE_REPORT_MANAGE", - name="Manage Compliance Reports", - description="The ability to create, update, and delete compliance reports" - ) - - manage_role = role_model.objects.using(db_alias).create( - name="ComplianceReporting", - description="Compliance Report Manager", - display_order=1 - ) - - role_permissions = [] - - role_permissions.append( - role_permission( - role=manage_role, - permission=manage_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_compliance_reporting_roles(apps, schema_editor): - """ - Removes the credit calculation permissions from roles - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - role_model = apps.get_model('api', 'Role') - - manage_permission = permission.objects.using(db_alias).filter( - code="COMPLIANCE_REPORT_MANAGE" - ).first() - - if manage_permission: - role_permission.objects.filter( - permission_id=manage_permission.id - ).delete() - - manage_permission.delete() - - manage_role = role_model.objects.using(db_alias).filter( - name="ComplianceReporting" - ).first() - - manage_role.delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0133_add_compliance_report_types_and_statuses'), - ] - - operations = [ - RunPython( - add_compliance_reporting_roles, - remove_compliance_reporting_roles - ) - ] diff --git a/backend/api/migrations/0135_auto_20190528_0110.py b/backend/api/migrations/0135_auto_20190528_0110.py deleted file mode 100644 index 9786eb79f..000000000 --- a/backend/api/migrations/0135_auto_20190528_0110.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-28 01:10 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0134_add_compliance_reporting_roles'), - ] - - operations = [ - migrations.CreateModel( - name='ScheduleC', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ], - options={ - 'db_table': 'compliance_report_schedule_c', - }, - ), - migrations.CreateModel( - name='ScheduleCRecord', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('schedule', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='records', to='api.ScheduleC')), - ], - options={ - 'db_table': 'compliance_report_schedule_c_record', - }, - ), - migrations.AddField( - model_name='compliancereport', - name='schedule_c', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='compliance_report', to='api.ScheduleC'), - ), - ] diff --git a/backend/api/migrations/0136_auto_20190528_0212.py b/backend/api/migrations/0136_auto_20190528_0212.py deleted file mode 100644 index dd7058ebe..000000000 --- a/backend/api/migrations/0136_auto_20190528_0212.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-28 02:12 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0135_auto_20190528_0110'), - ] - - operations = [ - migrations.AddField( - model_name='schedulecrecord', - name='expected_use', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ExpectedUse'), - preserve_default=False, - ), - migrations.AddField( - model_name='schedulecrecord', - name='fuel_class', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.FuelClass'), - preserve_default=False, - ), - migrations.AddField( - model_name='schedulecrecord', - name='fuel_type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel'), - preserve_default=False, - ), - migrations.AddField( - model_name='schedulecrecord', - name='quantity', - field=models.DecimalField(decimal_places=2, max_digits=20), - preserve_default=False, - ), - migrations.AddField( - model_name='schedulecrecord', - name='rationale', - field=models.CharField(blank=True, max_length=100, null=True), - ), - ] diff --git a/backend/api/migrations/0137_notionaltransfertype.py b/backend/api/migrations/0137_notionaltransfertype.py deleted file mode 100644 index 4ab38ed49..000000000 --- a/backend/api/migrations/0137_notionaltransfertype.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-29 16:18 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0136_auto_20190528_0212'), - ] - - operations = [ - migrations.CreateModel( - name='NotionalTransferType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('the_type', models.CharField(max_length=25, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notionaltransfertype_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_notionaltransfertype_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'notional_transfer_type', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0138_auto_20190530_1823.py b/backend/api/migrations/0138_auto_20190530_1823.py deleted file mode 100644 index a6a72b76b..000000000 --- a/backend/api/migrations/0138_auto_20190530_1823.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-05-30 18:23 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0137_notionaltransfertype'), - ] - - operations = [ - migrations.CreateModel( - name='ApprovedFuelProvision', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_approvedfuelprovision_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('fuel', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel')), - ], - options={ - 'db_table': 'approved_fuel_provision', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='CarbonIntensityDeterminationType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('the_type', models.CharField(blank=True, max_length=25, null=True, unique=True)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_carbonintensitydeterminationtype_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_carbonintensitydeterminationtype_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'carbon_intensity_determination_type', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='ProvisionOfTheAct', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('description', models.CharField(blank=True, max_length=1000, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_provisionoftheact_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('determination_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='fuel_provisions', to='api.CarbonIntensityDeterminationType')), - ('fuel', models.ManyToManyField(through='api.ApprovedFuelProvision', to='api.ApprovedFuel')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_provisionoftheact_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'fuel_provisions', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AddField( - model_name='approvedfuelprovision', - name='provision', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ProvisionOfTheAct'), - ), - migrations.AddField( - model_name='approvedfuelprovision', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_approvedfuelprovision_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AlterUniqueTogether( - name='approvedfuelprovision', - unique_together=set([('fuel', 'provision')]), - ), - ] diff --git a/backend/api/migrations/0139_auto_20190604_1750.py b/backend/api/migrations/0139_auto_20190604_1750.py deleted file mode 100644 index ad865a004..000000000 --- a/backend/api/migrations/0139_auto_20190604_1750.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-04 17:50 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0138_auto_20190530_1823'), - ] - - operations = [ - migrations.AddField( - model_name='provisionoftheact', - name='display_order', - field=models.IntegerField(default=1), - preserve_default=False, - ), - migrations.AddField( - model_name='provisionoftheact', - name='effective_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='provisionoftheact', - name='expiration_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AlterField( - model_name='provisionoftheact', - name='determination_type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='fuel_provision', to='api.CarbonIntensityDeterminationType'), - ), - migrations.AlterModelTable( - name='carbonintensitydeterminationtype', - table='determination_type', - ), - migrations.AlterModelTable( - name='provisionoftheact', - table='fuel_provision', - ), - ] diff --git a/backend/api/migrations/0140_fix_renewable_categories.py b/backend/api/migrations/0140_fix_renewable_categories.py deleted file mode 100644 index 3dcdc5ceb..000000000 --- a/backend/api/migrations/0140_fix_renewable_categories.py +++ /dev/null @@ -1,77 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_categories(apps, schema_editor): - """ - Fixes the default carbon intensity category for Renewable diesel and - Renewable gasoline - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - default_carbon_intensity_category = apps.get_model( - 'api', 'DefaultCarbonIntensityCategory') - - approved_fuel.objects.using(db_alias).filter( - name="Renewable diesel" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Renewable fuel in relation to diesel class fuel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Renewable gasoline" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Renewable fuel in relation to gasoline class fuel" - ) - ) - - -def revert_categories(apps, schema_editor): - """ - Reverts the changes - """ - db_alias = schema_editor.connection.alias - - approved_fuel = apps.get_model('api', 'ApprovedFuel') - default_carbon_intensity_category = apps.get_model( - 'api', 'DefaultCarbonIntensityCategory') - - approved_fuel.objects.using(db_alias).filter( - name="Renewable diesel" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Petroleum-based diesel" - ) - ) - - approved_fuel.objects.using(db_alias).filter( - name="Renewable gasoline" - ).update( - default_carbon_intensity_category=default_carbon_intensity_category - .objects.using(db_alias).get( - name="Petroleum-based gasoline" - ) - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0139_auto_20190604_1750'), - ] - - operations = [ - RunPython( - update_categories, - revert_categories - ) - ] diff --git a/backend/api/migrations/0141_auto_20190606_2119.py b/backend/api/migrations/0141_auto_20190606_2119.py deleted file mode 100644 index 30d23cef9..000000000 --- a/backend/api/migrations/0141_auto_20190606_2119.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-06 21:19 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0140_fix_renewable_categories'), - ] - - operations = [ - migrations.AddField( - model_name='approvedfuelprovision', - name='determination_type', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api.CarbonIntensityDeterminationType'), - ), - migrations.AddField( - model_name='provisionoftheact', - name='provision', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AlterUniqueTogether( - name='approvedfuelprovision', - unique_together=set([('fuel', 'provision', 'determination_type')]), - ), - ] diff --git a/backend/api/migrations/0142_auto_20190606_2119.py b/backend/api/migrations/0142_auto_20190606_2119.py deleted file mode 100644 index 71d95b64f..000000000 --- a/backend/api/migrations/0142_auto_20190606_2119.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-06 21:19 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0141_auto_20190606_2119'), - ] - - operations = [ - migrations.AlterField( - model_name='provisionoftheact', - name='determination_type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='provision_act', to='api.CarbonIntensityDeterminationType'), - ), - migrations.AlterModelTable( - name='approvedfuelprovision', - table='carbon_intensity_fuel_determination', - ), - migrations.AlterModelTable( - name='provisionoftheact', - table='provision_act', - ), - ] diff --git a/backend/api/migrations/0143_move_determination_types.py b/backend/api/migrations/0143_move_determination_types.py deleted file mode 100644 index a9e2fe99e..000000000 --- a/backend/api/migrations/0143_move_determination_types.py +++ /dev/null @@ -1,55 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_descriptions(apps, schema_editor): - """ - Updates the provision field with the description. - Updates the description with the determination_type description - """ - db_alias = schema_editor.connection.alias - - provision_act = apps.get_model('api', 'ProvisionOfTheAct') - determination_type = apps.get_model( - 'api', 'CarbonIntensityDeterminationType') - - provisions = provision_act.objects.using(db_alias).all() - - for provision_obj in provisions: - determination_type_obj = determination_type.objects.using( - db_alias).get(id=provision_obj.determination_type_id) - provision_obj.provision = provision_obj.description - provision_obj.description = determination_type_obj.description - provision_obj.save() - - -def revert_descriptions(apps, schema_editor): - """ - Reverts the changes - """ - db_alias = schema_editor.connection.alias - - provision_act = apps.get_model('api', 'ProvisionOfTheAct') - - provisions = provision_act.objects.using(db_alias).all() - - for provision_obj in provisions: - provision_obj.description = provision_obj.provision - provision_obj.provision = "" - provision_obj.save() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0142_auto_20190606_2119'), - ] - - operations = [ - RunPython( - update_descriptions, - revert_descriptions - ) - ] diff --git a/backend/api/migrations/0144_update_approved_fuel_xref.py b/backend/api/migrations/0144_update_approved_fuel_xref.py deleted file mode 100644 index 23a11c6d1..000000000 --- a/backend/api/migrations/0144_update_approved_fuel_xref.py +++ /dev/null @@ -1,52 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def update_determination_type(apps, schema_editor): - """ - Updates the provision field with the description. - Updates the description with the determination_type description - """ - db_alias = schema_editor.connection.alias - - approved_fuel_provision = apps.get_model('api', 'ApprovedFuelProvision') - provision_act = apps.get_model('api', 'ProvisionOfTheAct') - - rows = approved_fuel_provision.objects.using(db_alias).all() - - for row in rows: - provision = provision_act.objects.using(db_alias).get( - id=row.provision_id) - row.determination_type_id = provision.determination_type_id - row.save() - - -def remove_determination_type(apps, schema_editor): - """ - Reverts the changes - """ - db_alias = schema_editor.connection.alias - - approved_fuel_provision = apps.get_model('api', 'ApprovedFuelProvision') - - rows = approved_fuel_provision.objects.using(db_alias).all() - - for row in rows: - row.determination_type_id = None - row.save() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0143_move_determination_types'), - ] - - operations = [ - RunPython( - update_determination_type, - remove_determination_type - ) - ] diff --git a/backend/api/migrations/0145_auto_20190606_2202.py b/backend/api/migrations/0145_auto_20190606_2202.py deleted file mode 100644 index fda646211..000000000 --- a/backend/api/migrations/0145_auto_20190606_2202.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-06 22:02 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0144_update_approved_fuel_xref'), - ] - - operations = [ - migrations.RemoveField( - model_name='carbonintensitydeterminationtype', - name='description', - ), - migrations.AlterField( - model_name='approvedfuelprovision', - name='determination_type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.CarbonIntensityDeterminationType'), - ), - migrations.AlterField( - model_name='provisionoftheact', - name='provision', - field=models.CharField(max_length=100), - ), - ] diff --git a/backend/api/migrations/0146_remove_provisionoftheact_determination_type.py b/backend/api/migrations/0146_remove_provisionoftheact_determination_type.py deleted file mode 100644 index 8cbf9e635..000000000 --- a/backend/api/migrations/0146_remove_provisionoftheact_determination_type.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-06 22:26 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0145_auto_20190606_2202'), - ] - - operations = [ - migrations.RemoveField( - model_name='provisionoftheact', - name='determination_type', - ), - ] diff --git a/backend/api/migrations/0147_auto_20190606_2242.py b/backend/api/migrations/0147_auto_20190606_2242.py deleted file mode 100644 index 5638933d1..000000000 --- a/backend/api/migrations/0147_auto_20190606_2242.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-06 22:42 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0146_remove_provisionoftheact_determination_type'), - ] - - operations = [ - migrations.RenameField( - model_name='approvedfuelprovision', - old_name='provision', - new_name='provision_act', - ), - migrations.AlterUniqueTogether( - name='approvedfuelprovision', - unique_together=set([('fuel', 'provision_act', 'determination_type')]), - ), - ] diff --git a/backend/api/migrations/0148_auto_20190607_1452.py b/backend/api/migrations/0148_auto_20190607_1452.py deleted file mode 100644 index efc18026a..000000000 --- a/backend/api/migrations/0148_auto_20190607_1452.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-07 14:52 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0147_auto_20190606_2242'), - ] - - operations = [ - migrations.AddField( - model_name='carbonintensitydeterminationtype', - name='fuel', - field=models.ManyToManyField(through='api.ApprovedFuelProvision', to='api.ApprovedFuel'), - ), - migrations.AddField( - model_name='carbonintensitydeterminationtype', - name='provision_act', - field=models.ManyToManyField(through='api.ApprovedFuelProvision', to='api.ProvisionOfTheAct'), - ), - ] diff --git a/backend/api/migrations/0149_auto_20190612_0150.py b/backend/api/migrations/0149_auto_20190612_0150.py deleted file mode 100644 index eebd82cd6..000000000 --- a/backend/api/migrations/0149_auto_20190612_0150.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-12 01:50 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0148_auto_20190607_1452'), - ] - - operations = [ - migrations.CreateModel( - name='ScheduleA', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ], - options={ - 'db_table': 'compliance_report_schedule_a', - }, - ), - migrations.CreateModel( - name='ScheduleARecord', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('quantity', models.DecimalField(decimal_places=2, max_digits=20)), - ('trading_partner', models.CharField(max_length=200)), - ('postal_address', models.CharField(max_length=200)), - ('fuel_class', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.FuelClass')), - ('schedule', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='records', to='api.ScheduleA')), - ('transfer_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.NotionalTransferType')), - ], - options={ - 'db_table': 'compliance_report_schedule_a_record', - }, - ), - migrations.AddField( - model_name='compliancereport', - name='schedule_a', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='compliance_report', to='api.ScheduleA'), - ), - ] diff --git a/backend/api/migrations/0150_auto_20190619_1733.py b/backend/api/migrations/0150_auto_20190619_1733.py deleted file mode 100644 index 93c5fb11f..000000000 --- a/backend/api/migrations/0150_auto_20190619_1733.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-19 17:33 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0149_auto_20190612_0150'), - ] - - operations = [ - migrations.CreateModel( - name='ScheduleB', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ], - options={ - 'db_table': 'compliance_report_schedule_b', - }, - ), - migrations.CreateModel( - name='ScheduleBRecord', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('quantity', models.DecimalField(decimal_places=2, max_digits=20)), - ('fuel_class', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.FuelClass')), - ('fuel_code', models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='api.FuelCode')), - ('fuel_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel')), - ], - options={ - 'db_table': 'compliance_report_schedule_b_record', - }, - ), - migrations.AlterField( - model_name='provisionoftheact', - name='description', - field=models.CharField(blank=True, max_length=1000), - ), - migrations.AlterField( - model_name='provisionoftheact', - name='provision', - field=models.CharField(max_length=100, unique=True), - ), - migrations.AddField( - model_name='schedulebrecord', - name='provision_of_the_act', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ProvisionOfTheAct'), - ), - migrations.AddField( - model_name='schedulebrecord', - name='schedule', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='records', to='api.ScheduleB'), - ), - migrations.AddField( - model_name='compliancereport', - name='schedule_b', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='compliance_report', to='api.ScheduleB'), - ), - ] diff --git a/backend/api/migrations/0151_rename_table_sequences.py b/backend/api/migrations/0151_rename_table_sequences.py deleted file mode 100644 index 057006da9..000000000 --- a/backend/api/migrations/0151_rename_table_sequences.py +++ /dev/null @@ -1,81 +0,0 @@ -from django.db import connection, migrations -from django.db.migrations import RunPython - - -def rename_table_sequences(_apps, schema_editor): - """ - Renames the table sequences so they match what the name of the actual - tables are - """ - if connection.vendor == 'postgresql': - schema_editor.execute( - 'ALTER SEQUENCE carbon_intensity_determination_type_id_seq ' - 'RENAME TO determination_type_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE approved_fuel_provision_id_seq ' - 'RENAME TO carbon_intensity_fuel_determination_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE approved_fuel_id_seq ' - 'RENAME TO approved_fuel_type_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE fuel_transport_mode_id_seq ' - 'RENAME TO fuel_transport_mode_type_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE fuel_provisions_id_seq ' - 'RENAME TO provision_act_id_seq;' - ) - - -def revert_table_seuqneces(_apps, schema_editor): - """ - Reverts the changes - """ - if connection.vendor == 'postgresql': - schema_editor.execute( - 'ALTER SEQUENCE determination_type_id_seq ' - 'RENAME TO carbon_intensity_determination_type_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE carbon_intensity_fuel_determination_id_seq ' - 'RENAME TO approved_fuel_provision_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE approved_fuel_type_id_seq ' - 'RENAME TO approved_fuel_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE fuel_transport_mode_type_id_seq ' - 'RENAME TO fuel_transport_mode_id_seq;' - ) - - schema_editor.execute( - 'ALTER SEQUENCE provision_act_id_seq ' - 'RENAME TO fuel_provisions_id_seq;' - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0150_auto_20190619_1733'), - ] - - operations = [ - RunPython( - rename_table_sequences, - revert_table_seuqneces - ) - ] diff --git a/backend/api/migrations/0152_edit_organization_address_permission.py b/backend/api/migrations/0152_edit_organization_address_permission.py deleted file mode 100644 index 65a0d7431..000000000 --- a/backend/api/migrations/0152_edit_organization_address_permission.py +++ /dev/null @@ -1,59 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_permission(apps, schema_editor): - """ - Adds EDIT_FUEL_SUPPLIER permission and adds it to the Managing Users - role - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', "Permission") - role = apps.get_model('api', "Role") - role_permission = apps.get_model('api', "RolePermission") - - permission.objects.using(db_alias).create( - code="EDIT_FUEL_SUPPLIER", - description="Allows the user to update the address of their " - "organization", - name="Edit Organization Address" - ) - - role_permission.objects.using(db_alias).create( - role=role.objects.using(db_alias).get(name="FSAdmin"), - permission=permission.objects.using(db_alias).get( - code="EDIT_FUEL_SUPPLIER") - ) - - -def remove_permission(apps, schema_editor): - """ - Deletes the EDIT_FUEL_SUPPLIER permission. - Removes the permission from the Managing Users role first - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', "Permission") - role_permission = apps.get_model('api', "RolePermission") - - role_permission.objects.using(db_alias).filter( - permission__code="EDIT_FUEL_SUPPLIER", - role__name="FSAdmin").delete() - - permission.objects.using(db_alias).filter( - code="EDIT_FUEL_SUPPLIER" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0151_rename_table_sequences'), - ] - - operations = [ - RunPython(add_permission, remove_permission) - ] diff --git a/backend/api/migrations/0153_remove_organizationaddress_primary.py b/backend/api/migrations/0153_remove_organizationaddress_primary.py deleted file mode 100644 index bd35d4fa0..000000000 --- a/backend/api/migrations/0153_remove_organizationaddress_primary.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-04 20:49 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0152_edit_organization_address_permission'), - ] - - operations = [ - migrations.RemoveField( - model_name='organizationaddress', - name='primary', - ), - ] diff --git a/backend/api/migrations/0154_add_address_effective_dates.py b/backend/api/migrations/0154_add_address_effective_dates.py deleted file mode 100644 index ff3a71f5d..000000000 --- a/backend/api/migrations/0154_add_address_effective_dates.py +++ /dev/null @@ -1,44 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_effective_dates(apps, schema_editor): - """ - Adds effective dates to the organization addresses - """ - db_alias = schema_editor.connection.alias - - organization_address = apps.get_model('api', 'OrganizationAddress') - - organization_address.objects.using(db_alias).update( - effective_date="2017-01-01" - ) - - -def remove_effective_dates(apps, schema_editor): - """ - Sets the effective dates back to null for the organization addresses - """ - db_alias = schema_editor.connection.alias - - organization_address = apps.get_model('api', 'OrganizationAddress') - - organization_address.objects.using(db_alias).update( - effective_date=None - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0153_remove_organizationaddress_primary'), - ] - - operations = [ - RunPython( - add_effective_dates, - remove_effective_dates - ) - ] diff --git a/backend/api/migrations/0155_schedule_d.py b/backend/api/migrations/0155_schedule_d.py deleted file mode 100644 index 91b356c03..000000000 --- a/backend/api/migrations/0155_schedule_d.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-06-27 23:17 -from __future__ import unicode_literals - -import api.models.ComplianceReportSchedules -from decimal import Decimal -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0154_add_address_effective_dates'), - ] - - operations = [ - migrations.CreateModel( - name='ScheduleD', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ], - options={ - 'db_table': 'compliance_report_schedule_d', - }, - ), - migrations.CreateModel( - name='ScheduleDSheet', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('feedstock', models.CharField(blank=True, max_length=100, null=True)), - ('fuel_class', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.FuelClass')), - ('fuel_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel')), - ('schedule', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='sheets', to='api.ScheduleD')), - ], - options={ - 'db_table': 'compliance_report_schedule_d_sheet', - }, - ), - migrations.CreateModel( - name='ScheduleDSheetInput', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('worksheet_name', models.CharField(blank=True, max_length=100, null=True)), - ('cell', models.CharField(blank=True, max_length=100, null=True)), - ('value', models.CharField(blank=True, max_length=100, null=True)), - ('units', models.CharField(blank=True, max_length=100, null=True)), - ('description', models.CharField(blank=True, max_length=100, null=True)), - ('sheet', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='inputs', to='api.ScheduleDSheet')), - ], - options={ - 'db_table': 'compliance_report_schedule_d_sheet_input', - }, - ), - migrations.CreateModel( - name='ScheduleDSheetOutput', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('intensity', models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=5, null=True)), - ('description', models.CharField(blank=True, choices=[(api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Fuel Dispensing'), 'DISPENSING'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Fuel Distribution and Storage'), 'DISTRIBUTION'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Fuel Production'), 'PRODUCTION'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Feedstock Transmission'), 'FEEDSTOCK_TRANSMISSION'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Feedstock Recovery'), 'FEEDSTOCK_RECOVERY'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Feedstock Upgrading'), 'FEEDSTOCK_UPGRADING'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Land Use Change'), 'LAND_USE_CHANGE'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Fertilizer Manufacture'), 'FERTILIZER'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Gas Leaks and Flares'), 'GAS_LEAKS_AND_FLARES'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('CO₂ and H₂S Removed'), 'CO2_AND_H2S_REMOVED'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Emissions Displaced'), 'EMISSIONS_DISPLACED'), (api.models.ComplianceReportSchedules.ScheduleDSheetOutput.OutputCells('Fuel Use (High Heating Value)'), 'FUEL_USE_HIGH_HEATING_VALUE')], max_length=100, null=True)), - ('sheet', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='outputs', to='api.ScheduleDSheet')), - ], - options={ - 'db_table': 'compliance_report_schedule_d_sheet_output', - }, - ), - migrations.AddField( - model_name='compliancereport', - name='schedule_d', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='compliance_report', to='api.ScheduleD'), - ), - migrations.AlterUniqueTogether( - name='scheduledsheetoutput', - unique_together=set([('description', 'sheet')]), - ), - ] diff --git a/backend/api/migrations/0156_auto_20190716_0523.py b/backend/api/migrations/0156_auto_20190716_0523.py deleted file mode 100644 index 0babdbd4a..000000000 --- a/backend/api/migrations/0156_auto_20190716_0523.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-16 05:23 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0155_schedule_d'), - ] - - operations = [ - migrations.CreateModel( - name='ScheduleSummary', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('gasoline_class_retained', models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True)), - ('gasoline_class_deferred', models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True)), - ('diesel_class_retained', models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True)), - ('diesel_class_deferred', models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True)), - ], - options={ - 'db_table': 'compliance_report_summary', - }, - ), - migrations.AddField( - model_name='compliancereport', - name='summary', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='compliance_report', to='api.ScheduleSummary'), - ), - ] diff --git a/backend/api/migrations/0157_credittradecomment_is_deleted.py b/backend/api/migrations/0157_credittradecomment_is_deleted.py deleted file mode 100644 index 85bced0ac..000000000 --- a/backend/api/migrations/0157_credittradecomment_is_deleted.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-15 18:15 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0156_auto_20190716_0523'), - ] - - operations = [ - migrations.AddField( - model_name='credittradecomment', - name='is_deleted', - field=models.BooleanField(default=False), - ), - ] diff --git a/backend/api/migrations/0158_auto_20190716_2018.py b/backend/api/migrations/0158_auto_20190716_2018.py deleted file mode 100644 index 06e4b84e3..000000000 --- a/backend/api/migrations/0158_auto_20190716_2018.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-16 20:18 -from __future__ import unicode_literals - -from decimal import Decimal -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0157_credittradecomment_is_deleted'), - ] - - operations = [ - migrations.AlterField( - model_name='scheduledsheetoutput', - name='intensity', - field=models.DecimalField(blank=True, decimal_places=50, default=Decimal('0.00'), max_digits=100, null=True), - ), - ] diff --git a/backend/api/migrations/0159_schedulesummary_credits_offset.py b/backend/api/migrations/0159_schedulesummary_credits_offset.py deleted file mode 100644 index 38bd7bb88..000000000 --- a/backend/api/migrations/0159_schedulesummary_credits_offset.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-16 20:52 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0158_auto_20190716_2018'), - ] - - operations = [ - migrations.AddField( - model_name='schedulesummary', - name='credits_offset', - field=models.IntegerField(blank=True, null=True), - ), - ] diff --git a/backend/api/migrations/0160_auto_20190717_1830.py b/backend/api/migrations/0160_auto_20190717_1830.py deleted file mode 100644 index 9d3f36fab..000000000 --- a/backend/api/migrations/0160_auto_20190717_1830.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-17 18:30 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0159_schedulesummary_credits_offset'), - ] - - operations = [ - migrations.AlterField( - model_name='scheduledsheet', - name='fuel_class', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='api.FuelClass'), - ), - migrations.AlterField( - model_name='scheduledsheet', - name='fuel_type', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel'), - ), - ] diff --git a/backend/api/migrations/0161_auto_20190718_1421.py b/backend/api/migrations/0161_auto_20190718_1421.py deleted file mode 100644 index dbd46426e..000000000 --- a/backend/api/migrations/0161_auto_20190718_1421.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-18 14:21 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0160_auto_20190717_1830'), - ] - - operations = [ - migrations.AlterField( - model_name='scheduledsheet', - name='fuel_class', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.FuelClass'), - preserve_default=False, - ), - migrations.AlterField( - model_name='scheduledsheet', - name='fuel_type', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel'), - preserve_default=False, - ), - ] diff --git a/backend/api/migrations/0162_auto_20190718_0625.py b/backend/api/migrations/0162_auto_20190718_0625.py deleted file mode 100644 index 4dfd94288..000000000 --- a/backend/api/migrations/0162_auto_20190718_0625.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-18 06:25 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0161_auto_20190718_1421'), - ] - - operations = [ - migrations.AlterModelOptions( - name='schedulearecord', - options={'ordering': ['id']}, - ), - migrations.AlterModelOptions( - name='schedulebrecord', - options={'ordering': ['id']}, - ), - migrations.AlterModelOptions( - name='schedulecrecord', - options={'ordering': ['id']}, - ), - migrations.AlterModelOptions( - name='scheduledsheet', - options={'ordering': ['id']}, - ), - migrations.AlterModelOptions( - name='scheduledsheetinput', - options={'ordering': ['id']}, - ), - migrations.AddField( - model_name='schedulebrecord', - name='intensity', - field=models.DecimalField(blank=True, decimal_places=2, default=None, max_digits=5, null=True), - ), - migrations.AddField( - model_name='schedulebrecord', - name='schedule_d_sheet_index', - field=models.IntegerField(default=None, null=True), - ), - ] diff --git a/backend/api/migrations/0163_transactiontype.py b/backend/api/migrations/0163_transactiontype.py deleted file mode 100644 index 15c65be10..000000000 --- a/backend/api/migrations/0163_transactiontype.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-23 22:48 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0162_auto_20190718_0625'), - ] - - operations = [ - migrations.CreateModel( - name='TransactionType', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('display_order', models.IntegerField()), - ('effective_date', models.DateField(blank=True, null=True)), - ('expiration_date', models.DateField(blank=True, null=True)), - ('the_type', models.CharField(max_length=25, unique=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_transactiontype_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_transactiontype_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'transaction_type', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0164_auto_20190729_1810.py b/backend/api/migrations/0164_auto_20190729_1810.py deleted file mode 100644 index e66d96f01..000000000 --- a/backend/api/migrations/0164_auto_20190729_1810.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-07-29 18:10 -from __future__ import unicode_literals - -from api.models.SigningAuthorityAssertion import SigningAuthorityAssertion -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0163_transactiontype'), - ] - - operations = [ - migrations.AddField( - model_name='signingauthorityassertion', - name='module', - field=models.CharField(choices=[(SigningAuthorityAssertion.AssertionModules('credit_trade'), 'CREDIT_TRADE'), (SigningAuthorityAssertion.AssertionModules('compliance_report'), 'COMPLIANCE_REPORTING')], default='credit_trade', max_length=50), - ), - migrations.AddField( - model_name='signingauthorityconfirmation', - name='compliance_report', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='confirmations', to='api.ComplianceReport'), - ), - migrations.AlterField( - model_name='signingauthorityconfirmation', - name='credit_trade', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='confirmations', to='api.CreditTrade'), - ), - ] diff --git a/backend/api/migrations/0165_compliance_reporting_manager_role.py b/backend/api/migrations/0165_compliance_reporting_manager_role.py deleted file mode 100644 index 03db643c4..000000000 --- a/backend/api/migrations/0165_compliance_reporting_manager_role.py +++ /dev/null @@ -1,60 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_compliance_manager(apps, schema_editor): - """ - Renames the existing Compliance Report Manager to Compliance Reporting - Adds the Compliance Manager role for government - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', 'Role') - - role.objects.using(db_alias).filter( - name="ComplianceReporting" - ).update( - description="Compliance Reporting" - ) - - role.objects.using(db_alias).create( - name="GovComplianceManager", - description="Compliance Manager", - display_order=12, - is_government_role=True - ) - - -def remove_compliance_manager(apps, schema_editor): - """ - Removes the credit calculation permissions from roles - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', 'Role') - - role.objects.using(db_alias).filter( - name="GovComplianceManager" - ).delete() - - role.objects.using(db_alias).filter( - name="ComplianceReporting" - ).update( - description="Compliance Report Manager" - ) - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0164_auto_20190729_1810'), - ] - - operations = [ - RunPython( - add_compliance_manager, - remove_compliance_manager - ) - ] diff --git a/backend/api/migrations/0166_add_sign_compliance_report_permission.py b/backend/api/migrations/0166_add_sign_compliance_report_permission.py deleted file mode 100644 index 528d0b0d6..000000000 --- a/backend/api/migrations/0166_add_sign_compliance_report_permission.py +++ /dev/null @@ -1,65 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_compliance_report_signing_permission(apps, schema_editor): - """ - Adds the signing compliance report permission and attaches it to - the Signing Authority role - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - signing_permission = permission.objects.using(db_alias).create( - code="SIGN_COMPLIANCE_REPORT", - name="Sign a Compliance Report", - description="The ability to sign and execute a Credit Transfer " - "Proposal." - ) - - role_permission.objects.create( - role=role.objects.get(name="FSManager"), - permission=signing_permission - ) - - -def remove_compliance_report_signing_permission(apps, schema_editor): - """ - Removes the signing compliance report permission and removes it - from the role - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - signing_permission = permission.objects.using(db_alias).filter( - code="SIGN_COMPLIANCE_REPORT" - ).first() - - if signing_permission: - role_permission.objects.filter( - permission_id=signing_permission.id - ).delete() - - signing_permission.delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0165_compliance_reporting_manager_role'), - ] - - operations = [ - RunPython( - add_compliance_report_signing_permission, - remove_compliance_report_signing_permission - ) - ] diff --git a/backend/api/migrations/0167_compliancereporthistory.py b/backend/api/migrations/0167_compliancereporthistory.py deleted file mode 100644 index 0cbabc166..000000000 --- a/backend/api/migrations/0167_compliancereporthistory.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.22 on 2019-08-06 22:07 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0166_add_sign_compliance_report_permission'), - ] - - operations = [ - migrations.CreateModel( - name='ComplianceReportHistory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('compliance_report', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='compliance_reports', to='api.ComplianceReport')), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereporthistory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('status', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='compliance_reports', to='api.ComplianceReportStatus')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereporthistory_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ('user_role', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_reports', to='api.Role')), - ], - options={ - 'db_table': 'compliance_report_history', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0168_signingauthorityconfirmation_title.py b/backend/api/migrations/0168_signingauthorityconfirmation_title.py deleted file mode 100644 index f0be3b564..000000000 --- a/backend/api/migrations/0168_signingauthorityconfirmation_title.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.22 on 2019-08-06 22:53 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0167_compliancereporthistory'), - ] - - operations = [ - migrations.AddField( - model_name='signingauthorityconfirmation', - name='title', - field=models.CharField(blank=True, max_length=100, null=True), - ), - ] diff --git a/backend/api/migrations/0169_add_view_compliance_report_permission.py b/backend/api/migrations/0169_add_view_compliance_report_permission.py deleted file mode 100644 index 8c07db995..000000000 --- a/backend/api/migrations/0169_add_view_compliance_report_permission.py +++ /dev/null @@ -1,75 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_compliance_report_view_permission(apps, schema_editor): - """ - Adds the view compliance report permission and attaches it to - the Compliance Manager role and the Compliance Reporting role - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - view_permission = permission.objects.using(db_alias).create( - code="VIEW_COMPLIANCE_REPORT", - name="View Compliance Reports", - description="The ability to view compliance reports." - ) - - roles = role.objects.using(db_alias).filter(name__in=[ - "ComplianceReporting", "GovComplianceManager" - ]) - - role_permissions = [] - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=view_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_compliance_report_view_permission(apps, schema_editor): - """ - Removes the view compliance report permission and removes it - from the roles that had it - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - view_permission = permission.objects.using(db_alias).filter( - code="VIEW_COMPLIANCE_REPORT" - ).first() - - if view_permission: - role_permission.objects.filter( - permission_id=view_permission.id - ).delete() - - view_permission.delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0168_signingauthorityconfirmation_title'), - ] - - operations = [ - RunPython( - add_compliance_report_view_permission, - remove_compliance_report_view_permission - ) - ] diff --git a/backend/api/migrations/0170_auto_20190819_0126.py b/backend/api/migrations/0170_auto_20190819_0126.py deleted file mode 100644 index 9b7ab7ad8..000000000 --- a/backend/api/migrations/0170_auto_20190819_0126.py +++ /dev/null @@ -1,73 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-08-19 01:26 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -import django.contrib.postgres.fields.jsonb -import django.core.serializers.json -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0169_add_view_compliance_report_permission'), - ] - - operations = [ - migrations.CreateModel( - name='ComplianceReportSnapshot', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('snapshot', django.contrib.postgres.fields.jsonb.JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder, null=True)), - ], - options={ - 'db_table': 'compliance_report_snapshot', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_a', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleA'), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_b', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleB'), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_c', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleC'), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_d', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleD'), - ), - migrations.AlterField( - model_name='compliancereport', - name='summary', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleSummary'), - ), - migrations.AddField( - model_name='compliancereportsnapshot', - name='compliance_report', - field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='api.ComplianceReport'), - ), - migrations.AddField( - model_name='compliancereportsnapshot', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereportsnapshot_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='compliancereportsnapshot', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereportsnapshot_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0171_add_idir_compliance_report_permissions.py b/backend/api/migrations/0171_add_idir_compliance_report_permissions.py deleted file mode 100644 index 8fafa771b..000000000 --- a/backend/api/migrations/0171_add_idir_compliance_report_permissions.py +++ /dev/null @@ -1,159 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_idir_compliance_report_permissions(apps, schema_editor): - """ - Adds the Recommend Accept and Recommend Rejection for Government - Analyst role. - Adds the Recommend Accept and Recommend Rejection for Compliance - Manager role (These should be different from the ones above, so we - can distinguish them). - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - recommend_acceptance_perm = permission.objects.using(db_alias).create( - code="ANALYST_RECOMMEND_ACCEPTANCE_COMPLIANCE_REPORT", - name="Recommend Acceptance", - description="The ability to recommend approval of a compliance " - "report. (This is for Government Analyst)" - ) - - recommend_rejection_perm = permission.objects.using(db_alias).create( - code="ANALYST_RECOMMEND_REJECTION_COMPLIANCE_REPORT", - name="Recommend Rejection", - description="The ability to recommend rejection of a compliance " - "report. (This is for Government Analyst)" - ) - - role_analyst = role.objects.using(db_alias).get(name="GovUser") - - role_permissions = [] - - role_permissions.append( - role_permission( - role=role_analyst, - permission=recommend_acceptance_perm - ) - ) - - role_permissions.append( - role_permission( - role=role_analyst, - permission=recommend_rejection_perm - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - recommend_acceptance_perm = permission.objects.using(db_alias).create( - code="MANAGER_RECOMMEND_ACCEPTANCE_COMPLIANCE_REPORT", - name="Recommend Acceptance", - description="The ability to recommend approval of a compliance " - "report. (This is for Compliance Manager)" - ) - - recommend_rejection_perm = permission.objects.using(db_alias).create( - code="MANAGER_RECOMMEND_REJECTION_COMPLIANCE_REPORT", - name="Recommend Rejection", - description="The ability to recommend rejection of a compliance " - "report. (This is for Compliance Manager)" - ) - - role_manager = role.objects.using(db_alias).get( - name="GovComplianceManager" - ) - - role_permissions = [] - - role_permissions.append( - role_permission( - role=role_manager, - permission=recommend_acceptance_perm - ) - ) - - role_permissions.append( - role_permission( - role=role_manager, - permission=recommend_rejection_perm - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_idir_compliance_report_permissions(apps, schema_editor): - """ - Removes the view compliance report permission and removes it - from the roles that had it - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - acceptance_permission = permission.objects.using(db_alias).filter( - code="ANALYST_RECOMMEND_ACCEPTANCE_COMPLIANCE_REPORT" - ).first() - - if acceptance_permission: - role_permission.objects.filter( - permission_id=acceptance_permission.id - ).delete() - - acceptance_permission.delete() - - rejection_permission = permission.objects.using(db_alias).filter( - code="ANALYST_RECOMMEND_REJECTION_COMPLIANCE_REPORT" - ).first() - - if rejection_permission: - role_permission.objects.filter( - permission_id=rejection_permission.id - ).delete() - - rejection_permission.delete() - - acceptance_permission = permission.objects.using(db_alias).filter( - code="MANAGER_RECOMMEND_ACCEPTANCE_COMPLIANCE_REPORT" - ).first() - - if acceptance_permission: - role_permission.objects.filter( - permission_id=acceptance_permission.id - ).delete() - - acceptance_permission.delete() - - rejection_permission = permission.objects.using(db_alias).filter( - code="MANAGER_RECOMMEND_REJECTION_COMPLIANCE_REPORT" - ).first() - - if rejection_permission: - role_permission.objects.filter( - permission_id=rejection_permission.id - ).delete() - - rejection_permission.delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0170_auto_20190819_0126'), - ] - - operations = [ - RunPython( - add_idir_compliance_report_permissions, - remove_idir_compliance_report_permissions - ) - ] diff --git a/backend/api/migrations/0172_add_compliance_report_new_statuses.py b/backend/api/migrations/0172_add_compliance_report_new_statuses.py deleted file mode 100644 index 589386f13..000000000 --- a/backend/api/migrations/0172_add_compliance_report_new_statuses.py +++ /dev/null @@ -1,69 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_compliance_report_new_statuses(apps, schema_editor): - """ - Adds Basic Compliance Report Types and Statuses - """ - db_alias = schema_editor.connection.alias - - compliance_report_status = apps.get_model('api', 'ComplianceReportStatus') - - - compliance_report_status.objects.using(db_alias).bulk_create([ - compliance_report_status( - status='Unreviewed', - display_order=100, - ), - compliance_report_status( - status='Returned', - display_order=110, - ), - compliance_report_status( - status='Accepted', - display_order=1, - ), - compliance_report_status( - status='Rejected', - display_order=2, - ), - compliance_report_status( - status='Recommended', - display_order=3, - ), - compliance_report_status( - status='Not Recommended', - display_order=4, - ), - ]) - - -def remove_compliance_report_new_statuses(apps, schema_editor): - """ - Removes Basic Compliance Report Types and Statuses - """ - db_alias = schema_editor.connection.alias - compliance_report_status = apps.get_model('api', 'ComplianceReportStatus') - - compliance_report_status.objects.using(db_alias).get(status='Unreviewed').delete() - compliance_report_status.objects.using(db_alias).get(status='Accepted').delete() - compliance_report_status.objects.using(db_alias).get(status='Rejected').delete() - compliance_report_status.objects.using(db_alias).get(status='Returned').delete() - compliance_report_status.objects.using(db_alias).get(status='Recommended').delete() - compliance_report_status.objects.using(db_alias).get(status='Not Recommended').delete() - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0171_add_idir_compliance_report_permissions'), - ] - - operations = [ - RunPython( - add_compliance_report_new_statuses, - remove_compliance_report_new_statuses - ), - ] diff --git a/backend/api/migrations/0173_auto_20190819_1941.py b/backend/api/migrations/0173_auto_20190819_1941.py deleted file mode 100644 index 10ea6ff9b..000000000 --- a/backend/api/migrations/0173_auto_20190819_1941.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-08-19 19:41 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0172_add_compliance_report_new_statuses'), - ] - - operations = [ - migrations.CreateModel( - name='ComplianceReportWorkflowState', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('analyst_status', models.ForeignKey(default='Unreviewed', on_delete=django.db.models.deletion.CASCADE, related_name='+', to='api.ComplianceReportStatus', to_field='status')), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereportworkflowstate_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('director_status', models.ForeignKey(default='Unreviewed', on_delete=django.db.models.deletion.CASCADE, related_name='+', to='api.ComplianceReportStatus', to_field='status')), - ('fuel_supplier_status', models.ForeignKey(default='Draft', on_delete=django.db.models.deletion.CASCADE, related_name='+', to='api.ComplianceReportStatus', to_field='status')), - ('manager_status', models.ForeignKey(default='Unreviewed', on_delete=django.db.models.deletion.CASCADE, related_name='+', to='api.ComplianceReportStatus', to_field='status')), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereportworkflowstate_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'compliance_report_workflow_state', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.RemoveField( - model_name='compliancereport', - name='status', - ), - migrations.AddField( - model_name='compliancereport', - name='status_django_pacifier', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='compliance_report', to='api.ComplianceReportWorkflowState'), - ), - ] diff --git a/backend/api/migrations/0174_auto_20190819_1942.py b/backend/api/migrations/0174_auto_20190819_1942.py deleted file mode 100644 index f0c5abcb6..000000000 --- a/backend/api/migrations/0174_auto_20190819_1942.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-08-19 19:42 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0173_auto_20190819_1941'), - ] - - operations = [ - migrations.AlterField( - model_name='compliancereport', - name='status_django_pacifier', - field=models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='compliance_report', to='api.ComplianceReportWorkflowState'), - ), - ] diff --git a/backend/api/migrations/0175_auto_20190819_1942.py b/backend/api/migrations/0175_auto_20190819_1942.py deleted file mode 100644 index 6bfbd9c17..000000000 --- a/backend/api/migrations/0175_auto_20190819_1942.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-08-19 19:42 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0174_auto_20190819_1942'), - ] - - operations = [ - migrations.RenameField( - model_name='compliancereport', - old_name='status_django_pacifier', - new_name='status', - ), - ] diff --git a/backend/api/migrations/0176_auto_20190823_0131.py b/backend/api/migrations/0176_auto_20190823_0131.py deleted file mode 100644 index b4b346a0a..000000000 --- a/backend/api/migrations/0176_auto_20190823_0131.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-08-23 01:31 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0175_auto_20190819_1942'), - ] - - operations = [ - migrations.AlterField( - model_name='compliancereporthistory', - name='status', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='history_records', to='api.ComplianceReportWorkflowState'), - ), - ] diff --git a/backend/api/migrations/0177_auto_20190821_1837.py b/backend/api/migrations/0177_auto_20190821_1837.py deleted file mode 100644 index ac46e3e58..000000000 --- a/backend/api/migrations/0177_auto_20190821_1837.py +++ /dev/null @@ -1,75 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.22 on 2019-08-21 18:37 -from __future__ import unicode_literals - -import db_comments.model_mixins -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0176_auto_20190823_0131'), - ] - - operations = [ - migrations.CreateModel( - name='ExclusionAgreement', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ], - options={ - 'db_table': 'compliance_report_exclusion_agreement', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.CreateModel( - name='ExclusionAgreementRecord', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('transaction_partner', models.CharField(max_length=200)), - ('postal_address', models.CharField(max_length=200)), - ('quantity', models.DecimalField(decimal_places=0, max_digits=15)), - ('quantity_not_sold', models.DecimalField(decimal_places=0, max_digits=15)), - ('exclusion_agreement', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='records', to='api.ExclusionAgreement')), - ('fuel_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.ApprovedFuel')), - ('transaction_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='api.TransactionType')), - ], - options={ - 'db_table': 'compliance_report_exclusion_agreement_record', - 'ordering': ['id'], - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_a', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleA'), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_b', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleB'), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_c', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleC'), - ), - migrations.AlterField( - model_name='compliancereport', - name='schedule_d', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleD'), - ), - migrations.AlterField( - model_name='compliancereport', - name='summary', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ScheduleSummary'), - ), - migrations.AddField( - model_name='compliancereport', - name='exclusion_agreement', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='compliance_report', to='api.ExclusionAgreement'), - ), - ] diff --git a/backend/api/migrations/0178_documentfileattachment_scan_resubmit_ttl.py b/backend/api/migrations/0178_documentfileattachment_scan_resubmit_ttl.py deleted file mode 100644 index a7c0a8a9e..000000000 --- a/backend/api/migrations/0178_documentfileattachment_scan_resubmit_ttl.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-08-27 21:39 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0177_auto_20190821_1837'), - ] - - operations = [ - migrations.AddField( - model_name='documentfileattachment', - name='scan_resubmit_ttl', - field=models.IntegerField(default=200), - ), - ] diff --git a/backend/api/migrations/0179_db_column_adjustments_for_compliance_reporting.py b/backend/api/migrations/0179_db_column_adjustments_for_compliance_reporting.py deleted file mode 100644 index 64241422e..000000000 --- a/backend/api/migrations/0179_db_column_adjustments_for_compliance_reporting.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-08-27 16:08 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0178_documentfileattachment_scan_resubmit_ttl'), - ] - - operations = [ - migrations.AlterField( - model_name='compliancereportstatus', - name='status', - field=models.CharField(blank=True, max_length=25, unique=True), - ), - ] diff --git a/backend/api/migrations/0180_add_director_compliance_report_permissions.py b/backend/api/migrations/0180_add_director_compliance_report_permissions.py deleted file mode 100644 index 729cdb125..000000000 --- a/backend/api/migrations/0180_add_director_compliance_report_permissions.py +++ /dev/null @@ -1,103 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_director_compliance_report_permissions(apps, schema_editor): - """ - Adds the Approve, Reject and View Compliance Reports to - director positions - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - approve_permission = permission.objects.using(db_alias).create( - code="APPROVE_COMPLIANCE_REPORT", - name="Approve Compliance Report", - description="The ability to make a statuatory decision by approving " - "a compliance report" - ) - - reject_permission = permission.objects.using(db_alias).create( - code="REJECT_COMPLIANCE_REPORT", - name="Reject Compliance Report", - description="The ability to make a statuatory decision by rejecting " - "a compliance report" - ) - - view_permission = permission.objects.using(db_alias).get( - code="VIEW_COMPLIANCE_REPORT" - ) - - roles = role.objects.using(db_alias).filter( - name__in=["GovDirector", "GovDeputyDirector"] - ) - - role_permissions = [] - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=approve_permission - ) - ) - - role_permissions.append( - role_permission( - role=role, - permission=reject_permission - ) - ) - - role_permissions.append( - role_permission( - role=role, - permission=view_permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_director_compliance_report_permissions(apps, schema_editor): - """ - Removes the Approve, Reject and View Compliance Reports from - director positions - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model('api', 'Permission') - role_permission = apps.get_model('api', 'RolePermission') - - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "APPROVE_COMPLIANCE_REPORT", - "REJECT_COMPLIANCE_REPORT", - "VIEW_COMPLIANCE_REPORT" - ], - role__name__in=["GovDirector", "GovDeputyDirector"] - ).delete() - - permission.objects.using(db_alias).filter( - code__in=["APPROVE_COMPLIANCE_REPORT", "REJECT_COMPLIANCE_REPORT"] - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0179_db_column_adjustments_for_compliance_reporting'), - ] - - operations = [ - RunPython( - add_director_compliance_report_permissions, - remove_director_compliance_report_permissions - ) - ] diff --git a/backend/api/migrations/0181_auto_20190829_2036.py b/backend/api/migrations/0181_auto_20190829_2036.py deleted file mode 100644 index cdcdfdcca..000000000 --- a/backend/api/migrations/0181_auto_20190829_2036.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.22 on 2019-08-29 20:36 -from __future__ import unicode_literals - -import api.models.SigningAuthorityAssertion -from django.db import migrations, models - -from api.models.SigningAuthorityAssertion import SigningAuthorityAssertion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0180_add_director_compliance_report_permissions'), - ] - - operations = [ - migrations.AlterField( - model_name='signingauthorityassertion', - name='module', - field=models.CharField(choices=[(SigningAuthorityAssertion.AssertionModules('credit_trade'), 'CREDIT_TRADE'), (SigningAuthorityAssertion.AssertionModules('compliance_report'), 'COMPLIANCE_REPORTING'), (SigningAuthorityAssertion.AssertionModules('exclusion_report'), 'EXCLUSION_REPORTS')], default='credit_trade', max_length=50), - ), - ] diff --git a/backend/api/migrations/0182_compliancereport_credit_transaction.py b/backend/api/migrations/0182_compliancereport_credit_transaction.py deleted file mode 100644 index 85f679811..000000000 --- a/backend/api/migrations/0182_compliancereport_credit_transaction.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-09-09 20:20 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0181_auto_20190829_2036'), - ] - - operations = [ - migrations.AddField( - model_name='compliancereport', - name='credit_transaction', - field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='compliance_report', to='api.CreditTrade'), - ), - ] diff --git a/backend/api/migrations/0183_add_gov_analyst_view_compliance_report_permission.py b/backend/api/migrations/0183_add_gov_analyst_view_compliance_report_permission.py deleted file mode 100644 index e09eb1af9..000000000 --- a/backend/api/migrations/0183_add_gov_analyst_view_compliance_report_permission.py +++ /dev/null @@ -1,55 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_gov_analyst_view_compliance_report_permission(apps, schema_editor): - """ - Adds the View Compliance Report to the Gov Analyst role - """ - db_alias = schema_editor.connection.alias - - permission = apps.get_model( - 'api', 'Permission') - role = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - view_permission = permission.objects.using(db_alias).get( - code="VIEW_COMPLIANCE_REPORT" - ) - - role = role.objects.using(db_alias).get(name="GovUser") - - role_permission.objects.using(db_alias).create( - role=role, - permission=view_permission - ) - - -def remove_gov_analyst_view_compliance_report_permission(apps, schema_editor): - """ - Removes the View Compliance Reports from the Gov Analyst role - """ - db_alias = schema_editor.connection.alias - - role_permission = apps.get_model('api', 'RolePermission') - - role_permission.objects.using(db_alias).filter( - permission__code="VIEW_COMPLIANCE_REPORT", - role__name="GovUser" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0182_compliancereport_credit_transaction'), - ] - - operations = [ - RunPython( - add_gov_analyst_view_compliance_report_permission, - remove_gov_analyst_view_compliance_report_permission - ) - ] diff --git a/backend/api/migrations/0184_add_request_supplemental_report_status.py b/backend/api/migrations/0184_add_request_supplemental_report_status.py deleted file mode 100644 index 6e53a035d..000000000 --- a/backend/api/migrations/0184_add_request_supplemental_report_status.py +++ /dev/null @@ -1,44 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_request_supplemental_report_status(apps, schema_editor): - """ - Adds Requested Supplemental to compliance report statuses - """ - db_alias = schema_editor.connection.alias - - compliance_report_status = apps.get_model('api', 'ComplianceReportStatus') - - compliance_report_status.objects.using(db_alias).create( - status='Requested Supplemental', - display_order=120 - ) - - -def remove_request_supplemental_report_status(apps, schema_editor): - """ - Removes Requested Supplemental from compliance report statuses - """ - db_alias = schema_editor.connection.alias - compliance_report_status = apps.get_model('api', 'ComplianceReportStatus') - - compliance_report_status.objects.using(db_alias).get( - status='Requested Supplemental' - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0183_add_gov_analyst_view_compliance_report_permission'), - ] - - operations = [ - RunPython( - add_request_supplemental_report_status, - remove_request_supplemental_report_status - ), - ] diff --git a/backend/api/migrations/0185_compliancereport_supplements.py b/backend/api/migrations/0185_compliancereport_supplements.py deleted file mode 100644 index 8050ae9ad..000000000 --- a/backend/api/migrations/0185_compliancereport_supplements.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-09-16 17:44 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0184_add_request_supplemental_report_status'), - ] - - operations = [ - migrations.AddField( - model_name='compliancereport', - name='supplements', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='supplemental_reports', to='api.ComplianceReport'), - ), - ] diff --git a/backend/api/migrations/0186_compliancereport_nickname.py b/backend/api/migrations/0186_compliancereport_nickname.py deleted file mode 100644 index 99034a0ea..000000000 --- a/backend/api/migrations/0186_compliancereport_nickname.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-09-17 17:20 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0185_compliancereport_supplements'), - ] - - operations = [ - migrations.AddField( - model_name='compliancereport', - name='nickname', - field=models.CharField(blank=True, max_length=255, null=True), - ), - ] diff --git a/backend/api/migrations/0187_auto_20190923_1556.py b/backend/api/migrations/0187_auto_20190923_1556.py deleted file mode 100644 index a9371906a..000000000 --- a/backend/api/migrations/0187_auto_20190923_1556.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.23 on 2019-09-23 15:56 -from __future__ import unicode_literals - -import api.notifications.notification_types -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0186_compliancereport_nickname'), - ] - - operations = [ - migrations.AddField( - model_name='notificationmessage', - name='related_report', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='api.ComplianceReport'), - ), - migrations.AlterField( - model_name='notificationsubscription', - name='notification_type', - field=models.CharField(choices=[(api.notifications.notification_types.NotificationType('Credit Transfer Proposal Created'), 'Credit Transfer Proposal Created'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 1/2'), 'Credit Transfer Proposal Signed 1/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Signed 2/2'), 'Credit Transfer Proposal Signed 2/2'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Refused'), 'Credit Transfer Proposal Refused'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Accepted'), 'Credit Transfer Proposal Accepted'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Approval'), 'Credit Transfer Proposal Recommended For Approval'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Recommended For Declination'), 'Credit Transfer Proposal Recommended For Declination'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Declined'), 'Credit Transfer Proposal Declined'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Approved'), 'Credit Transfer Proposal Approved'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Rescinded'), 'Credit Transfer Proposal Rescinded'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Comment Created Or Updated'), 'Credit Transfer Proposal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('Credit Transfer Proposal Internal Comment Created Or Updated'), 'Credit Transfer Proposal Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Created'), 'PVR Created'), (api.notifications.notification_types.NotificationType('PVR Recommended For Approval'), 'PVR Recommended For Approval'), (api.notifications.notification_types.NotificationType('PVR Rescinded'), 'PVR Rescinded'), (api.notifications.notification_types.NotificationType('PVR Pulled Back'), 'PVR Pulled Back'), (api.notifications.notification_types.NotificationType('PVR Declined'), 'PVR Declined'), (api.notifications.notification_types.NotificationType('PVR Approved'), 'PVR Approved'), (api.notifications.notification_types.NotificationType('PVR Comment Created Or Updated'), 'PVR Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Internal Comment Created Or Updated'), 'PVR Internal Comment Created Or Updated'), (api.notifications.notification_types.NotificationType('PVR Returned to Analyst'), 'PVR Returned to Analyst'), (api.notifications.notification_types.NotificationType('Document Pending Submission'), 'Document Pending Submission'), (api.notifications.notification_types.NotificationType('Document Submitted'), 'Document Submitted'), (api.notifications.notification_types.NotificationType('Document Security Scan Failed'), 'Document Security Scan Failed'), (api.notifications.notification_types.NotificationType('Document Received'), 'Document Received'), (api.notifications.notification_types.NotificationType('Document Archived'), 'Document Archived'), (api.notifications.notification_types.NotificationType('Compliance Report Draft Saved'), 'Compliance Report Draft Saved'), (api.notifications.notification_types.NotificationType('Compliance Report Submitted'), 'Compliance Report Submitted'), (api.notifications.notification_types.NotificationType('Compliance Report Recommended for Acceptance - Analyst'), 'Compliance Report Recommended for Acceptance - Analyst'), (api.notifications.notification_types.NotificationType('Compliance Report Recommended for Rejection - Analyst'), 'Compliance Report Recommended for Rejection - Analyst'), (api.notifications.notification_types.NotificationType('Compliance Report Recommended for Acceptance - Manager'), 'Compliance Report Recommended for Acceptance - Manager'), (api.notifications.notification_types.NotificationType('Compliance Report Recommended for Rejection - Manager'), 'Compliance Report Recommended for Rejection - Manager'), (api.notifications.notification_types.NotificationType('Compliance Report Accepted'), 'Compliance Report Accepted'), (api.notifications.notification_types.NotificationType('Compliance Report Rejected'), 'Compliance Report Rejected'), (api.notifications.notification_types.NotificationType('Compliance Report Requested Supplemental'), 'Compliance Report Requested Supplemental'), (api.notifications.notification_types.NotificationType('Exclusion Report Draft Saved'), 'Exclusion Report Draft Saved'), (api.notifications.notification_types.NotificationType('Exclusion Report Submitted'), 'Exclusion Report Submitted'), (api.notifications.notification_types.NotificationType('Exclusion Report Recommended for Acceptance - Analyst'), 'Exclusion Report Recommended for Acceptance - Analyst'), (api.notifications.notification_types.NotificationType('Exclusion Report Recommended for Rejection - Analyst'), 'Exclusion Report Recommended for Rejection - Analyst'), (api.notifications.notification_types.NotificationType('Exclusion Report Recommended for Acceptance - Manager'), 'Exclusion Report Recommended for Acceptance - Manager'), (api.notifications.notification_types.NotificationType('Exclusion Report Recommended for Rejection - Manager'), 'Exclusion Report Recommended for Rejection - Manager'), (api.notifications.notification_types.NotificationType('Exclusion Report Accepted'), 'Exclusion Report Accepted'), (api.notifications.notification_types.NotificationType('Exclusion Report Rejected'), 'Exclusion Report Rejected'), (api.notifications.notification_types.NotificationType('Exclusion Report Requested Supplemental'), 'Exclusion Report Requested Supplemental')], max_length=128), - ), - ] diff --git a/backend/api/migrations/0188_update_roles_permissions.py b/backend/api/migrations/0188_update_roles_permissions.py deleted file mode 100644 index dfdc564de..000000000 --- a/backend/api/migrations/0188_update_roles_permissions.py +++ /dev/null @@ -1,250 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_permissions(apps, schema_editor): - """ - Adds the missing permissions from certain roles - """ - db_alias = schema_editor.connection.alias - - permission_model = apps.get_model( - 'api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - # Compliance Reporting - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "FUEL_CODES_VIEW", - "CREDIT_CALCULATION_VIEW" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="ComplianceReporting" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # Signing Authority - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "EDIT_FUEL_SUPPLIER", "VIEW_COMPLIANCE_REPORT" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="FSManager" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # File Submission - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "FUEL_CODES_VIEW" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="FSDocSubmit" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # File Submission (Government) - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "EDIT_PRIVILEGED_COMMENTS", - "DOCUMENTS_LINK_TO_CREDIT_TRADE", "USE_HISTORICAL_DATA_ENTRY", - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS", - "VIEW_APPROVED_CREDIT_TRANSFERS" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="GovDoc" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # Administrator - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "EDIT_PRIVILEGED_COMMENTS", "EDIT_FUEL_SUPPLIER", - "VIEW_PRIVILEGED_COMMENTS" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="Admin" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # Director / Deputy Director - roles = role_model.objects.using(db_alias).filter(name__in=[ - "GovDeputyDirector", "GovDirector" - ]) - - role_permissions = [] - - for role in roles: - role_permissions.append( - role_permission( - role=role, - permission=permission_model.objects.using(db_alias).get( - code="DOCUMENTS_VIEW" - ) - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # Compliance Manager - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "ADD_COMMENT", "FUEL_CODES_VIEW", - "PROPOSE_CREDIT_TRANSFER", "CREDIT_CALCULATION_MANAGE", - "FUEL_CODES_MANAGE", "EDIT_PRIVILEGED_COMMENTS", - "DOCUMENTS_LINK_TO_CREDIT_TRADE", "EDIT_FUEL_SUPPLIERS", - "RECOMMEND_CREDIT_TRANSFER", "RESCIND_CREDIT_TRANSFER", - "DOCUMENTS_GOVERNMENT_REVIEW", "USE_HISTORICAL_DATA_ENTRY", - "CREDIT_CALCULATION_VIEW", "DOCUMENTS_VIEW", "VIEW_FUEL_SUPPLIERS" - "VIEW_PRIVILEGED_COMMENTS", "VIEW_APPROVED_CREDIT_TRANSFERS" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="GovComplianceManager" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_permissions(apps, schema_editor): - """ - Removes the permissions that were added - """ - db_alias = schema_editor.connection.alias - - role_permission = apps.get_model('api', 'RolePermission') - - # Compliance Reporting - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "FUEL_CODES_VIEW", - "CREDIT_CALCULATION_VIEW" - ], - role__name="ComplianceReporting" - ).delete() - - # Signing Authority - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "EDIT_FUEL_SUPPLIER", "VIEW_COMPLIANCE_REPORT" - ], - role__name="FSManager" - ).delete() - - # File Submission - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "FUEL_CODES_VIEW" - ], - role__name="FSDocSubmit" - ).delete() - - # File Submission (Government) - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "EDIT_PRIVILEGED_COMMENTS", - "DOCUMENTS_LINK_TO_CREDIT_TRADE", "USE_HISTORICAL_DATA_ENTRY", - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS", - "VIEW_APPROVED_CREDIT_TRANSFERS" - ], - role__name="GovDoc" - ).delete() - - # Administrator - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "EDIT_PRIVILEGED_COMMENTS", "EDIT_FUEL_SUPPLIER", - "VIEW_PRIVILEGED_COMMENTS" - ], - role__name="Admin" - ).delete() - - # Director / Deputy Director - role_permission.objects.using(db_alias).filter( - permission__code="DOCUMENTS_VIEW", - role__name__in=["GovDeputyDirector", "GovDirector"] - ).delete() - - # Compliance Manager - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "LOGIN", "VIEW_CREDIT_TRANSFERS", "ADD_COMMENT", "FUEL_CODES_VIEW", - "PROPOSE_CREDIT_TRANSFER", "CREDIT_CALCULATION_MANAGE", - "FUEL_CODES_MANAGE", "EDIT_PRIVILEGED_COMMENTS", - "DOCUMENTS_LINK_TO_CREDIT_TRADE", "EDIT_FUEL_SUPPLIERS", - "RECOMMEND_CREDIT_TRANSFER", "RESCIND_CREDIT_TRANSFER", - "DOCUMENTS_GOVERNMENT_REVIEW", "USE_HISTORICAL_DATA_ENTRY", - "CREDIT_CALCULATION_VIEW", "DOCUMENTS_VIEW", "VIEW_FUEL_SUPPLIERS" - "VIEW_PRIVILEGED_COMMENTS", "VIEW_APPROVED_CREDIT_TRANSFERS" - ], - role__name="GovComplianceManager" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0187_auto_20190923_1556'), - ] - - operations = [ - RunPython( - add_permissions, - remove_permissions - ) - ] diff --git a/backend/api/migrations/0189_auto_20190930_2245.py b/backend/api/migrations/0189_auto_20190930_2245.py deleted file mode 100644 index 745969c8b..000000000 --- a/backend/api/migrations/0189_auto_20190930_2245.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.23 on 2019-09-30 22:45 -from __future__ import unicode_literals - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0188_update_roles_permissions'), - ] - - operations = [ - migrations.AddField( - model_name='compliancereporttype', - name='create_timestamp', - field=models.DateTimeField(auto_now_add=True, null=True), - ), - migrations.AddField( - model_name='compliancereporttype', - name='create_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereporttype_CREATE_USER', to=settings.AUTH_USER_MODEL), - ), - migrations.AddField( - model_name='compliancereporttype', - name='effective_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='compliancereporttype', - name='expiration_date', - field=models.DateField(blank=True, null=True), - ), - migrations.AddField( - model_name='compliancereporttype', - name='update_timestamp', - field=models.DateTimeField(auto_now=True, null=True), - ), - migrations.AddField( - model_name='compliancereporttype', - name='update_user', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_compliancereporttype_UPDATE_USER', to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/backend/api/migrations/0190_compliancereport_supplemental_note.py b/backend/api/migrations/0190_compliancereport_supplemental_note.py deleted file mode 100644 index 3ee3e40b6..000000000 --- a/backend/api/migrations/0190_compliancereport_supplemental_note.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.21 on 2019-10-03 23:14 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0189_auto_20190930_2245'), - ] - - operations = [ - migrations.AddField( - model_name='compliancereport', - name='supplemental_note', - field=models.CharField(blank=True, max_length=500, null=True), - ), - ] diff --git a/backend/api/migrations/0191_role_default_role.py b/backend/api/migrations/0191_role_default_role.py deleted file mode 100644 index d61c64ed1..000000000 --- a/backend/api/migrations/0191_role_default_role.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.23 on 2019-10-02 21:27 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0190_compliancereport_supplemental_note'), - ] - - operations = [ - migrations.AddField( - model_name='role', - name='default_role', - field=models.BooleanField(default=False), - ), - ] diff --git a/backend/api/migrations/0192_update_guest_role.py b/backend/api/migrations/0192_update_guest_role.py deleted file mode 100644 index 97213dd9c..000000000 --- a/backend/api/migrations/0192_update_guest_role.py +++ /dev/null @@ -1,48 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def set_default_role(apps, schema_editor): - """ - Set FSNoAccess (Guest) as a default role - """ - db_alias = schema_editor.connection.alias - - role = apps.get_model('api', 'Role') - - guest_role = role.objects.using(db_alias).get(name="FSNoAccess") - - guest_role.default_role = True - guest_role.save() - - -def remove_default_role(apps, schema_editor): - """ - Unflag all default roles - """ - db_alias = schema_editor.connection.alias - - role_model = apps.get_model('api', 'Role') - default_roles = role_model.objects.using(db_alias).filter( - default_role=True - ) - - for role in default_roles: - role.default_role = False - role.save() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0191_role_default_role'), - ] - - operations = [ - RunPython( - set_default_role, - remove_default_role - ) - ] diff --git a/backend/api/migrations/0193_auto_20191017_1601.py b/backend/api/migrations/0193_auto_20191017_1601.py deleted file mode 100644 index 6e187d2a2..000000000 --- a/backend/api/migrations/0193_auto_20191017_1601.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.23 on 2019-10-17 16:01 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0192_update_guest_role'), - ] - - operations = [ - migrations.AddField( - model_name='schedulesummary', - name='diesel_class_obligation', - field=models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True), - ), - migrations.AddField( - model_name='schedulesummary', - name='diesel_class_previously_retained', - field=models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True), - ), - migrations.AddField( - model_name='schedulesummary', - name='gasoline_class_obligation', - field=models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True), - ), - migrations.AddField( - model_name='schedulesummary', - name='gasoline_class_previously_retained', - field=models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True), - ), - ] diff --git a/backend/api/migrations/0194_auto_20191112_2114.py b/backend/api/migrations/0194_auto_20191112_2114.py deleted file mode 100644 index a55255772..000000000 --- a/backend/api/migrations/0194_auto_20191112_2114.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.23 on 2019-11-12 21:14 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0193_auto_20191017_1601'), - ] - - operations = [ - migrations.RemoveField( - model_name='documentmilestone', - name='create_user', - ), - migrations.RemoveField( - model_name='documentmilestone', - name='document', - ), - migrations.RemoveField( - model_name='documentmilestone', - name='update_user', - ), - migrations.AddField( - model_name='document', - name='milestone', - field=models.CharField(blank=True, max_length=1000, null=True), - ), - migrations.AddField( - model_name='documenthistory', - name='milestone', - field=models.CharField(blank=True, max_length=1000, null=True), - ), - migrations.DeleteModel( - name='DocumentMilestone', - ), - ] diff --git a/backend/api/migrations/0195_audit_additional_tables.py b/backend/api/migrations/0195_audit_additional_tables.py deleted file mode 100644 index 1923c96b9..000000000 --- a/backend/api/migrations/0195_audit_additional_tables.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - -from api.migrations.operations.trigger_operation import AuditTable - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0194_auto_20191112_2114'), - ] - - _tables = ['compliance_report_snapshot', - 'compliance_report', - 'document', - 'document_file', - 'fuel_code', - 'notification_message', - 'compliance_report_summary', - 'compliance_report_summary', - 'compliance_report_schedule_a', - 'compliance_report_schedule_a_record', - 'compliance_report_schedule_b', - 'compliance_report_schedule_b_record', - 'compliance_report_schedule_c', - 'compliance_report_schedule_c_record', - 'compliance_report_schedule_d', - 'compliance_report_schedule_d_sheet', - 'compliance_report_schedule_d_sheet_input', - 'compliance_report_schedule_d_sheet_output', - 'compliance_report_exclusion_agreement', - 'compliance_report_exclusion_agreement_record' - ] - - operations = [AuditTable(table) for table in _tables] diff --git a/backend/api/migrations/0196_auto_20191121_1607.py b/backend/api/migrations/0196_auto_20191121_1607.py deleted file mode 100644 index 334028bee..000000000 --- a/backend/api/migrations/0196_auto_20191121_1607.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.23 on 2019-11-21 16:07 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0195_audit_additional_tables'), - ] - - operations = [ - migrations.AlterUniqueTogether( - name='fuelcode', - unique_together=set([('fuel_code', 'fuel_code_version', 'fuel_code_version_minor', 'status')]), - ), - ] diff --git a/backend/api/migrations/0197_update_guest_permissions.py b/backend/api/migrations/0197_update_guest_permissions.py deleted file mode 100644 index aee669723..000000000 --- a/backend/api/migrations/0197_update_guest_permissions.py +++ /dev/null @@ -1,112 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_permissions(apps, schema_editor): - """ - Adds the some permissions to the guest role - Adjusts some permissions from the compliance manager - """ - db_alias = schema_editor.connection.alias - - permission_model = apps.get_model('api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - # Guest - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "VIEW_COMPLIANCE_REPORT", "DOCUMENTS_VIEW", "FUEL_CODES_VIEW", - "CREDIT_CALCULATION_VIEW" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="FSNoAccess" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # Compliance Reporting - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="ComplianceReporting" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - role_permission.objects.using(db_alias).filter( - permission__code="ADD_COMMENT", - role__name="FSAdmin" - ).delete() - - -def remove_permissions(apps, schema_editor): - """ - Reverts the permissions back to how it was - """ - db_alias = schema_editor.connection.alias - - permission_model = apps.get_model('api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - # Compliance Reporting - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS" - ], - role__name="ComplianceReporting" - ).delete() - - # Managing Users - role_permission.objects.using(db_alias).create( - role=role_model.objects.using(db_alias).get( - name="FSAdmin" - ), - permission=permission_model.objects.using(db_alias).get( - code="ADD_COMMENT" - ) - ) - - # Guest - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "VIEW_COMPLIANCE_REPORT", "DOCUMENTS_VIEW", "FUEL_CODES_VIEW", - "CREDIT_CALCULATION_VIEW" - ], - role__name="FSNoAccess" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0196_auto_20191121_1607'), - ] - - operations = [ - RunPython( - add_permissions, - remove_permissions - ) - ] diff --git a/backend/api/migrations/0198_update_compliance_report_permissions.py b/backend/api/migrations/0198_update_compliance_report_permissions.py deleted file mode 100644 index c8f119431..000000000 --- a/backend/api/migrations/0198_update_compliance_report_permissions.py +++ /dev/null @@ -1,95 +0,0 @@ -from django.db import migrations -from django.db.migrations import RunPython - - -def add_permissions(apps, schema_editor): - """ - Adds the some permissions to the guest role - Adjusts some permissions from the compliance manager - """ - db_alias = schema_editor.connection.alias - - permission_model = apps.get_model('api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - # Compliance Reporting - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS" - ], - role__name="ComplianceReporting" - ).delete() - - # Compliance Manager (IDIR) - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="GovComplianceManager" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - -def remove_permissions(apps, schema_editor): - """ - Reverts the permissions back to how it was - """ - db_alias = schema_editor.connection.alias - - permission_model = apps.get_model('api', 'Permission') - role_model = apps.get_model('api', 'Role') - role_permission = apps.get_model('api', 'RolePermission') - - # Compliance Reporting - permissions = permission_model.objects.using(db_alias).filter(code__in=[ - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS" - ]) - - role_permissions = [] - - for permission in permissions: - role_permissions.append( - role_permission( - role=role_model.objects.using(db_alias).get( - name="ComplianceReporting" - ), - permission=permission - ) - ) - - role_permission.objects.using(db_alias).bulk_create(role_permissions) - - # Compliance Manager (IDIR) - role_permission.objects.using(db_alias).filter( - permission__code__in=[ - "VIEW_FUEL_SUPPLIERS", "VIEW_PRIVILEGED_COMMENTS" - ], - role__name="GovComplianceManager" - ).delete() - - -class Migration(migrations.Migration): - """ - Attaches the functions for the migrations - """ - dependencies = [ - ('api', '0197_update_guest_permissions'), - ] - - operations = [ - RunPython( - add_permissions, - remove_permissions - ) - ] diff --git a/backend/api/migrations/0199_auto_20210421_1925.py b/backend/api/migrations/0199_auto_20210421_1925.py deleted file mode 100644 index bac8709c5..000000000 --- a/backend/api/migrations/0199_auto_20210421_1925.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.23 on 2021-04-21 19:25 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0198_update_compliance_report_permissions'), - ] - - operations = [ - migrations.AddField( - model_name='schedulesummary', - name='credits_offset_a', - field=models.IntegerField(blank=True, null=True), - ), - migrations.AddField( - model_name='schedulesummary', - name='credits_offset_b', - field=models.IntegerField(blank=True, null=True), - ), - ] diff --git a/backend/api/migrations/0200_auto_20221102_2220.py b/backend/api/migrations/0200_auto_20221102_2220.py deleted file mode 100644 index ac3fda7fb..000000000 --- a/backend/api/migrations/0200_auto_20221102_2220.py +++ /dev/null @@ -1,60 +0,0 @@ -# Generated by Django 3.2.10 on 2022-11-02 22:20 - -import django.core.serializers.json -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0199_auto_20210421_1925'), - ] - - operations = [ - migrations.AlterField( - model_name='compliancereportsnapshot', - name='compliance_report', - field=models.OneToOneField(on_delete=django.db.models.deletion.DO_NOTHING, to='api.compliancereport'), - ), - migrations.AlterField( - model_name='compliancereportsnapshot', - name='snapshot', - field=models.JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder, null=True), - ), - migrations.AlterField( - model_name='compliancereportworkflowstate', - name='analyst_status', - field=models.ForeignKey(default='Unreviewed', on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='api.compliancereportstatus', to_field='status'), - ), - migrations.AlterField( - model_name='compliancereportworkflowstate', - name='director_status', - field=models.ForeignKey(default='Unreviewed', on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='api.compliancereportstatus', to_field='status'), - ), - migrations.AlterField( - model_name='compliancereportworkflowstate', - name='fuel_supplier_status', - field=models.ForeignKey(default='Draft', on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='api.compliancereportstatus', to_field='status'), - ), - migrations.AlterField( - model_name='compliancereportworkflowstate', - name='manager_status', - field=models.ForeignKey(default='Unreviewed', on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='api.compliancereportstatus', to_field='status'), - ), - migrations.AlterField( - model_name='documenttype', - name='category', - field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='types', to='api.documentcategory'), - ), - migrations.AlterField( - model_name='user', - name='first_name', - field=models.CharField(blank=True, max_length=150, verbose_name='first name'), - ), - migrations.AlterField( - model_name='user', - name='last_name', - field=models.CharField(blank=True, max_length=150, verbose_name='last name'), - ), - ] diff --git a/backend/api/migrations/0201_user_keycloak_user_id.py b/backend/api/migrations/0201_user_keycloak_user_id.py deleted file mode 100644 index d0060caa6..000000000 --- a/backend/api/migrations/0201_user_keycloak_user_id.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2.10 on 2022-11-09 21:36 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0200_auto_20221102_2220'), - ] - - operations = [ - migrations.AddField( - model_name='user', - name='keycloak_user_id', - field=models.CharField(blank=True, max_length=150, null=True), - ), - ] diff --git a/backend/api/migrations/0202_create_user_login_history.py b/backend/api/migrations/0202_create_user_login_history.py deleted file mode 100644 index c89d8e9a7..000000000 --- a/backend/api/migrations/0202_create_user_login_history.py +++ /dev/null @@ -1,35 +0,0 @@ -# Generated by Django 3.2.16 on 2023-02-02 20:59 - -import db_comments.model_mixins -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0201_user_keycloak_user_id'), - ] - - operations = [ - migrations.CreateModel( - name='UserLoginHistory', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), - ('update_timestamp', models.DateTimeField(auto_now=True, null=True)), - ('keycloak_email', models.EmailField(max_length=254)), - ('external_username', models.CharField(blank=True, max_length=150, null=True)), - ('keycloak_user_id', models.CharField(blank=True, max_length=150, null=True)), - ('is_login_successful', models.BooleanField(default=False)), - ('login_error_message', models.CharField(blank=True, max_length=500, null=True)), - ('create_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_userloginhistory_CREATE_USER', to=settings.AUTH_USER_MODEL)), - ('update_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='api_userloginhistory_UPDATE_USER', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'db_table': 'user_login_history', - }, - bases=(models.Model, db_comments.model_mixins.DBComments), - ), - ] diff --git a/backend/api/migrations/0203_auto_20230312_0823.py b/backend/api/migrations/0203_auto_20230312_0823.py deleted file mode 100644 index 1d315cdbe..000000000 --- a/backend/api/migrations/0203_auto_20230312_0823.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.2.18 on 2023-03-12 08:23 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0202_create_user_login_history'), - ] - - operations = [ - migrations.AlterField( - model_name='scheduledsheetinput', - name='description', - field=models.CharField(blank=True, max_length=255, null=True), - ), - migrations.AlterField( - model_name='scheduledsheetinput', - name='value', - field=models.CharField(blank=True, max_length=255, null=True), - ), - ] diff --git a/backend/api/migrations/0204_auto_20230321_0204.py b/backend/api/migrations/0204_auto_20230321_0204.py deleted file mode 100644 index 377a64f1d..000000000 --- a/backend/api/migrations/0204_auto_20230321_0204.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.2.18 on 2023-03-21 02:04 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0203_auto_20230312_0823'), - ] - - operations = [ - migrations.RunSQL( - "UPDATE organization_address SET address_line_2 = address_line_2 || ' ' || address_line_3;" - ), - migrations.RunSQL( - "UPDATE organization_address SET state = state || ' ' || county" - ), - ] diff --git a/backend/api/migrations/0205_auto_20230321_0206.py b/backend/api/migrations/0205_auto_20230321_0206.py deleted file mode 100644 index a147ead48..000000000 --- a/backend/api/migrations/0205_auto_20230321_0206.py +++ /dev/null @@ -1,56 +0,0 @@ -# Generated by Django 3.2.18 on 2023-03-21 02:06 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0204_auto_20230321_0204'), - ] - - operations = [ - migrations.RemoveField( - model_name='organizationaddress', - name='address_line_3', - ), - migrations.RemoveField( - model_name='organizationaddress', - name='county', - ), - migrations.AddField( - model_name='organizationaddress', - name='attorney_address_other', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AddField( - model_name='organizationaddress', - name='attorney_city', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AddField( - model_name='organizationaddress', - name='attorney_country', - field=models.CharField(blank=True, max_length=100, null=True), - ), - migrations.AddField( - model_name='organizationaddress', - name='attorney_postal_code', - field=models.CharField(blank=True, max_length=10, null=True), - ), - migrations.AddField( - model_name='organizationaddress', - name='attorney_province', - field=models.CharField(blank=True, max_length=50, null=True), - ), - migrations.AddField( - model_name='organizationaddress', - name='attorney_representativename', - field=models.CharField(blank=True, max_length=500, null=True), - ), - migrations.AddField( - model_name='organizationaddress', - name='attorney_street_address', - field=models.CharField(blank=True, max_length=500, null=True), - ), - ] diff --git a/backend/api/migrations/0206_schedulesummary_credits_offset_c.py b/backend/api/migrations/0206_schedulesummary_credits_offset_c.py deleted file mode 100644 index e84869a18..000000000 --- a/backend/api/migrations/0206_schedulesummary_credits_offset_c.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.2.18 on 2023-03-22 22:46 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0205_auto_20230321_0206'), - ] - - operations = [ - migrations.AddField( - model_name='schedulesummary', - name='credits_offset_c', - field=models.IntegerField(blank=True, null=True), - ), - ] \ No newline at end of file diff --git a/backend/api/migrations/0207_alter_notificationsubscription_notification_type.py b/backend/api/migrations/0207_alter_notificationsubscription_notification_type.py deleted file mode 100644 index f4fd9533f..000000000 --- a/backend/api/migrations/0207_alter_notificationsubscription_notification_type.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.2.18 on 2023-04-26 03:38 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0206_schedulesummary_credits_offset_c'), - ] - - # The "choices" attribute of the field below was changed so that the actual values (the first argument of each choice, or pair) - # match what is actually being saved in the database, which is the string value of an enum member of NotificationType. - # Previously, those actual values were the enum members themselves, and so when get_notification_type_display() was called - # on a NotificationSubscription model instance, we would not get the intended value. - - operations = [ - migrations.AlterField( - model_name='notificationsubscription', - name='notification_type', - field=models.CharField(choices=[('NotificationType.CREDIT_TRANSFER_CREATED', 'Credit Transfer Proposal Created'), ('NotificationType.CREDIT_TRANSFER_SIGNED_1OF2', 'Credit Transfer Proposal Signed 1/2'), ('NotificationType.CREDIT_TRANSFER_SIGNED_2OF2', 'Credit Transfer Proposal Signed 2/2'), ('NotificationType.CREDIT_TRANSFER_PROPOSAL_REFUSED', 'Credit Transfer Proposal Refused'), ('NotificationType.CREDIT_TRANSFER_PROPOSAL_ACCEPTED', 'Credit Transfer Proposal Accepted'), ('NotificationType.CREDIT_TRANSFER_RECOMMENDED_FOR_APPROVAL', 'Credit Transfer Proposal Recommended For Approval'), ('NotificationType.CREDIT_TRANSFER_RECOMMENDED_FOR_DECLINATION', 'Credit Transfer Proposal Recommended For Declination'), ('NotificationType.CREDIT_TRANSFER_DECLINED', 'Credit Transfer Proposal Declined'), ('NotificationType.CREDIT_TRANSFER_APPROVED', 'Credit Transfer Proposal Approved'), ('NotificationType.CREDIT_TRANSFER_RESCINDED', 'Credit Transfer Proposal Rescinded'), ('NotificationType.CREDIT_TRANSFER_COMMENT', 'Credit Transfer Proposal Comment Created Or Updated'), ('NotificationType.CREDIT_TRANSFER_INTERNAL_COMMENT', 'Credit Transfer Proposal Internal Comment Created Or Updated'), ('NotificationType.PVR_CREATED', 'PVR Created'), ('NotificationType.PVR_RECOMMENDED_FOR_APPROVAL', 'PVR Recommended For Approval'), ('NotificationType.PVR_RESCINDED', 'PVR Rescinded'), ('NotificationType.PVR_PULLED_BACK', 'PVR Pulled Back'), ('NotificationType.PVR_DECLINED', 'PVR Declined'), ('NotificationType.PVR_APPROVED', 'PVR Approved'), ('NotificationType.PVR_COMMENT', 'PVR Comment Created Or Updated'), ('NotificationType.PVR_INTERNAL_COMMENT', 'PVR Internal Comment Created Or Updated'), ('NotificationType.PVR_RETURNED_TO_ANALYST', 'PVR Returned to Analyst'), ('NotificationType.DOCUMENT_PENDING_SUBMISSION', 'Document Pending Submission'), ('NotificationType.DOCUMENT_SUBMITTED', 'Document Submitted'), ('NotificationType.DOCUMENT_SCAN_FAILED', 'Document Security Scan Failed'), ('NotificationType.DOCUMENT_RECEIVED', 'Document Received'), ('NotificationType.DOCUMENT_ARCHIVED', 'Document Archived'), ('NotificationType.COMPLIANCE_REPORT_DRAFT', 'Compliance Report Draft Saved'), ('NotificationType.COMPLIANCE_REPORT_SUBMITTED', 'Compliance Report Submitted'), ('NotificationType.COMPLIANCE_REPORT_RECOMMENDED_FOR_ACCEPTANCE_ANALYST', 'Compliance Report Recommended for Acceptance - Analyst'), ('NotificationType.COMPLIANCE_REPORT_RECOMMENDED_FOR_REJECTION_ANALYST', 'Compliance Report Recommended for Rejection - Analyst'), ('NotificationType.COMPLIANCE_REPORT_RECOMMENDED_FOR_ACCEPTANCE_MANAGER', 'Compliance Report Recommended for Acceptance - Manager'), ('NotificationType.COMPLIANCE_REPORT_RECOMMENDED_FOR_REJECTION_MANAGER', 'Compliance Report Recommended for Rejection - Manager'), ('NotificationType.COMPLIANCE_REPORT_ACCEPTED', 'Compliance Report Accepted'), ('NotificationType.COMPLIANCE_REPORT_REJECTED', 'Compliance Report Rejected'), ('NotificationType.COMPLIANCE_REPORT_REQUESTED_SUPPLEMENTAL', 'Compliance Report Requested Supplemental'), ('NotificationType.EXCLUSION_REPORT_DRAFT', 'Exclusion Report Draft Saved'), ('NotificationType.EXCLUSION_REPORT_SUBMITTED', 'Exclusion Report Submitted'), ('NotificationType.EXCLUSION_REPORT_RECOMMENDED_FOR_ACCEPTANCE_ANALYST', 'Exclusion Report Recommended for Acceptance - Analyst'), ('NotificationType.EXCLUSION_REPORT_RECOMMENDED_FOR_REJECTION_ANALYST', 'Exclusion Report Recommended for Rejection - Analyst'), ('NotificationType.EXCLUSION_REPORT_RECOMMENDED_FOR_ACCEPTANCE_MANAGER', 'Exclusion Report Recommended for Acceptance - Manager'), ('NotificationType.EXCLUSION_REPORT_RECOMMENDED_FOR_REJECTION_MANAGER', 'Exclusion Report Recommended for Rejection - Manager'), ('NotificationType.EXCLUSION_REPORT_ACCEPTED', 'Exclusion Report Accepted'), ('NotificationType.EXCLUSION_REPORT_REJECTED', 'Exclusion Report Rejected'), ('NotificationType.EXCLUSION_REPORT_REQUESTED_SUPPLEMENTAL', 'Exclusion Report Requested Supplemental')], max_length=128), - ), - ] diff --git a/backend/api/services/ComplianceReportService.py b/backend/api/services/ComplianceReportService.py index 4f837af78..b18015228 100644 --- a/backend/api/services/ComplianceReportService.py +++ b/backend/api/services/ComplianceReportService.py @@ -285,7 +285,7 @@ def create_director_transactions(compliance_report, creating_user): # Code 26C is used to identify credits that must be refunded to the supplier. # This occurs when our debit position decreases and we have already spent credits. # In such cases, any excess credits must be returned to the supplier. - if is_supplemental and Decimal(lines['26C']) > 0: + if is_supplemental and Decimal(lines.get('26C', 0)) > 0: print("*** DIRECTOR 26C Increase to Credits ***") required_credit_transaction = Decimal(lines['26C']) diff --git a/backend/api/viewsets/ComplianceReport.py b/backend/api/viewsets/ComplianceReport.py index e5466b579..8a52314e8 100644 --- a/backend/api/viewsets/ComplianceReport.py +++ b/backend/api/viewsets/ComplianceReport.py @@ -553,12 +553,11 @@ def paginated(self, request): queryset = self.get_queryset() page = self.paginate_queryset(queryset) sorts = request.data.get('sorts') - if sorts: - if request.data.get('sorts')[0].get('id') == 'updateTimestamp': - if request.data.get('sorts')[0].get('desc'): - page = sorted(page, key=lambda x: [x.sort_date]) - else: - page = sorted(page, key=lambda x: [x.sort_date], reverse=True) + if sorts and request.data.get('sorts')[0].get('id') == 'updateTimestamp': + if request.data.get('sorts')[0].get('desc'): + page = sorted(page, key=lambda x: [x.update_timestamp]) + else: + page = sorted(page, key=lambda x: [x.update_timestamp], reverse=True) if page is not None: serializer = self.get_serializer(page, many=True) diff --git a/charts/tfrs-spilo/values-dev.yaml b/charts/tfrs-spilo/values-dev.yaml index 1586e8aa1..a51647b97 100644 --- a/charts/tfrs-spilo/values-dev.yaml +++ b/charts/tfrs-spilo/values-dev.yaml @@ -31,11 +31,11 @@ spilo: resources: limits: - cpu: 120m - memory: 400Mi + cpu: 200m + memory: 600Mi requests: - cpu: 60m - memory: 200Mi + cpu: 100m + memory: 300Mi podDisruptionBudget: enabled: false diff --git a/frontend/package.json b/frontend/package.json index 17d624b96..a73e06146 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "tfrs", - "version": "2.7.0", + "version": "2.8.0", "dependencies": { "@babel/eslint-parser": "^7.19.1", "@babel/plugin-proposal-object-rest-spread": "^7.20.7", diff --git a/openshift-v4/templates/backup-container-2.6.1/cronjob.md b/openshift-v4/templates/backup-container-2.6.1/cronjob.md new file mode 100644 index 000000000..a4d6af610 --- /dev/null +++ b/openshift-v4/templates/backup-container-2.6.1/cronjob.md @@ -0,0 +1,29 @@ +# Cronjob prerequisites +Backup PVC: backup +KNP: allow CronJob to connect to Spilo + +# Create database backup cronjob +oc process -f ./db-backup-cronjob-2.6.1.yaml \ +JOB_NAME=tfrs-db-backup \ +JOB_PERSISTENT_STORAGE_NAME=backup \ +SCHEDULE="00 08,20 * * *" \ +TAG_NAME=2.6.1 \ +DATABASE_SERVICE_NAME=tfrs-spilo-readonly \ +DATABASE_DEFAULT_PORT=5432 \ +DATABASE_NAME=tfrs \ +DATABASE_DEPLOYMENT_NAME=tfrs-patroni-app \ +DATABASE_USER_KEY_NAME=app-db-username \ +DATABASE_PASSWORD_KEY_NAME=app-db-password \ +BACKUP_STRATEGY=rolling \ +BACKUP_DIR=/backups \ +DAILY_BACKUPS=30 \ +WEEKLY_BACKUPS=8 \ +MONTHLY_BACKUPS=2 | oc apply -f - -n 0ab226-test + +# Create minio backup cronjob +oc process -f ./minio-backup-cronjob-2.6.1.yaml \ +JOB_NAME=tfrs-minio-backup \ +JOB_PERSISTENT_STORAGE_NAME=backup \ +SCHEDULE="0 12 * * *" \ +MINIO_CLAIM_NAME=tfrs-minio-test \ +TAG_NAME=2.6.1 | oc apply -f - -n 0ab226-test diff --git a/openshift-v4/templates/backup-container-2.6.1/db-backup-cronjob-2.6.1.yaml b/openshift-v4/templates/backup-container-2.6.1/db-backup-cronjob-2.6.1.yaml new file mode 100644 index 000000000..e36f96287 --- /dev/null +++ b/openshift-v4/templates/backup-container-2.6.1/db-backup-cronjob-2.6.1.yaml @@ -0,0 +1,253 @@ +--- +kind: "Template" +apiVersion: "template.openshift.io/v1" +metadata: + name: "{$JOB_NAME}-cronjob-template" + annotations: + description: "Scheduled Task to perform a Database Backup" + tags: "cronjob,backup" +parameters: + - name: "JOB_NAME" + displayName: "Job Name" + description: "Name of the Scheduled Job to Create." + value: "backup-postgres" + required: true + - name: "JOB_PERSISTENT_STORAGE_NAME" + displayName: "Backup Persistent Storage Name" + description: "Pre-Created PVC to use for backup target" + value: "bk-devex-von-tools-a9vlgd1jpsg1" + required: true + - name: "SCHEDULE" + displayName: "Cron Schedule" + description: "Cron Schedule to Execute the Job (using local cluster system TZ)" + # Currently targeting 1:00 AM Daily + value: "0 1 * * *" + required: true + - name: "SOURCE_IMAGE_NAME" + displayName: "Source Image Name" + description: "The name of the image to use for this resource." + required: true + value: "backup-container" + - name: "IMAGE_REGISTRY" + description: "The base OpenShift docker registry" + displayName: "Docker Image Registry" + required: true + # Set value to "docker-registry.default.svc:5000" if using OCP3 + value: "docker.io" + - name: "IMAGE_NAMESPACE" + displayName: "Image Namespace" + description: "The namespace of the OpenShift project containing the imagestream for the application." + required: true + value: "bcgovimages" + - name: "TAG_NAME" + displayName: "Environment TAG name" + description: "The TAG name for this environment, e.g., dev, test, prod" + required: true + value: "dev" + - name: "DATABASE_SERVICE_NAME" + displayName: "Database Service Name" + description: "The name of the database service." + required: true + value: "postgresql" + - name: "DATABASE_DEFAULT_PORT" + displayName: "Database Service Port" + description: "The configured port for the database service" + required: true + value: "5432" + - name: "DATABASE_NAME" + displayName: "Database Name" + description: "The name of the database." + required: true + value: "MyDatabase" + - name: "DATABASE_DEPLOYMENT_NAME" + displayName: "Database Deployment Name" + description: "The name associated to the database deployment resources. In particular, this is used to wire up the credentials associated to the database." + required: true + value: "postgresql" + - name: DATABASE_USER_KEY_NAME + displayName: Database User Key Name + description: + The database user key name stored in database deployment resources specified + by DATABASE_DEPLOYMENT_NAME. + required: true + value: database-user + - name: DATABASE_PASSWORD_KEY_NAME + displayName: Database Password Key Name + description: + The database password key name stored in database deployment resources + specified by DATABASE_DEPLOYMENT_NAME. + required: true + value: database-password + - name: "BACKUP_STRATEGY" + displayName: "Backup Strategy" + description: "The strategy to use for backups; for example daily, or rolling." + required: true + value: "rolling" + - name: "BACKUP_DIR" + displayName: "The root backup directory" + description: "The name of the root backup directory" + required: true + value: "/backups/" + - name: "NUM_BACKUPS" + displayName: "The number of backup files to be retained" + description: "The number of backup files to be retained. Used for the `daily` backup strategy. Ignored when using the `rolling` backup strategy." + required: false + value: "5" + - name: "DAILY_BACKUPS" + displayName: "Number of Daily Backups to Retain" + description: "The number of daily backup files to be retained. Used for the `rolling` backup strategy." + required: false + value: "7" + - name: "WEEKLY_BACKUPS" + displayName: "Number of Weekly Backups to Retain" + description: "The number of weekly backup files to be retained. Used for the `rolling` backup strategy." + required: false + value: "4" + - name: "MONTHLY_BACKUPS" + displayName: "Number of Monthly Backups to Retain" + description: "The number of monthly backup files to be retained. Used for the `rolling` backup strategy." + required: false + value: "1" + - name: "JOB_SERVICE_ACCOUNT" + displayName: "Service Account Name" + description: "Name of the Service Account To Exeucte the Job As." + value: "default" + required: true + - name: "SUCCESS_JOBS_HISTORY_LIMIT" + displayName: "Successful Job History Limit" + description: "The number of successful jobs that will be retained" + value: "5" + required: true + - name: "FAILED_JOBS_HISTORY_LIMIT" + displayName: "Failed Job History Limit" + description: "The number of failed jobs that will be retained" + value: "2" + required: true + - name: "JOB_BACKOFF_LIMIT" + displayName: "Job Backoff Limit" + description: "The number of attempts to try for a successful job outcome" + value: "0" + required: false +objects: +- kind: ConfigMap + apiVersion: v1 + metadata: + name: "${JOB_NAME}-config" + labels: + template: "${JOB_NAME}-config-template" + cronjob: "${JOB_NAME}" + data: + DATABASE_SERVICE_NAME: "${DATABASE_SERVICE_NAME}" + DEFAULT_PORT: "${DATABASE_DEFAULT_PORT}" + POSTGRESQL_DATABASE: "${DATABASE_NAME}" + # BACKUP_STRATEGY: "daily" + BACKUP_STRATEGY: "rolling" + RETENTION.NUM_BACKUPS: "${NUM_BACKUPS}" + RETENTION.DAILY_BACKUPS: "${DAILY_BACKUPS}" + RETENTION.WEEKLY_BACKUPS: "${WEEKLY_BACKUPS}" + RETENTION.MONTHLY_BACKUPS: "${MONTHLY_BACKUPS}" + +- kind: "CronJob" + apiVersion: "batch/v1" + metadata: + name: "${JOB_NAME}" + labels: + template: "${JOB_NAME}-cronjob" + cronjob: "${JOB_NAME}" + spec: + schedule: "${SCHEDULE}" + concurrencyPolicy: "Forbid" + successfulJobsHistoryLimit: "${{SUCCESS_JOBS_HISTORY_LIMIT}}" + failedJobsHistoryLimit: "${{FAILED_JOBS_HISTORY_LIMIT}}" + jobTemplate: + metadata: + labels: + template: "${JOB_NAME}-job" + cronjob: "${JOB_NAME}" + spec: + backoffLimit: ${{JOB_BACKOFF_LIMIT}} + template: + metadata: + labels: + template: "${JOB_NAME}-job" + cronjob: "${JOB_NAME}" + spec: + containers: + - name: "${JOB_NAME}-cronjob" + image: "${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/${SOURCE_IMAGE_NAME}:${TAG_NAME}" + # image: backup + command: + - "/bin/bash" + - "-c" + - "/backup.sh -1" + volumeMounts: + - mountPath: "${BACKUP_DIR}" + name: "backup" + env: + - name: BACKUP_DIR + value: "${BACKUP_DIR}/db-backups-by-cron/" + - name: BACKUP_STRATEGY + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: BACKUP_STRATEGY + - name: NUM_BACKUPS + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: RETENTION.NUM_BACKUPS + optional: true + - name: DAILY_BACKUPS + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: RETENTION.DAILY_BACKUPS + optional: true + - name: WEEKLY_BACKUPS + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: RETENTION.WEEKLY_BACKUPS + optional: true + - name: MONTHLY_BACKUPS + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: RETENTION.MONTHLY_BACKUPS + optional: true + - name: DATABASE_SERVICE_NAME + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: DATABASE_SERVICE_NAME + - name: DEFAULT_PORT + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: DEFAULT_PORT + optional: true + - name: POSTGRESQL_DATABASE + valueFrom: + configMapKeyRef: + name: "${JOB_NAME}-config" + key: POSTGRESQL_DATABASE + - name: DATABASE_USER + valueFrom: + secretKeyRef: + name: "${DATABASE_DEPLOYMENT_NAME}" + key: "${DATABASE_USER_KEY_NAME}" + - name: DATABASE_PASSWORD + valueFrom: + secretKeyRef: + name: "${DATABASE_DEPLOYMENT_NAME}" + key: "${DATABASE_PASSWORD_KEY_NAME}" + volumes: + - name: backup + persistentVolumeClaim: + claimName: "${JOB_PERSISTENT_STORAGE_NAME}" + restartPolicy: "Never" + terminationGracePeriodSeconds: 30 + activeDeadlineSeconds: 1600 + dnsPolicy: "ClusterFirst" + serviceAccountName: "${JOB_SERVICE_ACCOUNT}" + serviceAccount: "${JOB_SERVICE_ACCOUNT}" diff --git a/openshift-v4/templates/backup-container-2.6.1/minio-backup-cronjob-2.6.1.yaml b/openshift-v4/templates/backup-container-2.6.1/minio-backup-cronjob-2.6.1.yaml new file mode 100644 index 000000000..c523636fc --- /dev/null +++ b/openshift-v4/templates/backup-container-2.6.1/minio-backup-cronjob-2.6.1.yaml @@ -0,0 +1,130 @@ +--- +kind: "Template" +apiVersion: "template.openshift.io/v1" +metadata: + name: "{$JOB_NAME}-cronjob-template" + annotations: + description: "Scheduled Task to perform a Database Backup" + tags: "cronjob,backup" +parameters: + - name: "JOB_NAME" + displayName: "Job Name" + description: "Name of the Scheduled Job to Create." + value: "backup-postgres" + required: true + - name: "JOB_PERSISTENT_STORAGE_NAME" + displayName: "Backup Persistent Storage Name" + description: "Pre-Created PVC to use for backup target" + value: "bk-devex-von-tools-a9vlgd1jpsg1" + required: true + - name: "SCHEDULE" + displayName: "Cron Schedule" + description: "Cron Schedule to Execute the Job (using local cluster system TZ)" + # Currently targeting 1:00 AM Daily + value: "0 1 * * *" + required: true + - name: "SOURCE_IMAGE_NAME" + displayName: "Source Image Name" + description: "The name of the image to use for this resource." + required: true + value: "backup-container" + - name: "IMAGE_REGISTRY" + description: "The base OpenShift docker registry" + displayName: "Docker Image Registry" + required: true + # Set value to "docker-registry.default.svc:5000" if using OCP3 + value: "docker.io" + - name: "IMAGE_NAMESPACE" + displayName: "Image Namespace" + description: "The namespace of the OpenShift project containing the imagestream for the application." + required: true + value: "bcgovimages" + - name: "TAG_NAME" + displayName: "Environment TAG name" + description: "The TAG name for this environment, e.g., dev, test, prod" + required: true + value: "dev" + - name: "BACKUP_DIR" + displayName: "The root backup directory" + description: "The name of the root backup directory" + required: true + value: "/backups/" + - name: "MINIO_CLAIM_NAME" + displayName: "The Minio PVC name" + description: "The Minio PVC name" + required: true + - name: "JOB_SERVICE_ACCOUNT" + displayName: "Service Account Name" + description: "Name of the Service Account To Exeucte the Job As." + value: "default" + required: true + - name: "SUCCESS_JOBS_HISTORY_LIMIT" + displayName: "Successful Job History Limit" + description: "The number of successful jobs that will be retained" + value: "5" + required: true + - name: "FAILED_JOBS_HISTORY_LIMIT" + displayName: "Failed Job History Limit" + description: "The number of failed jobs that will be retained" + value: "2" + required: true + - name: "JOB_BACKOFF_LIMIT" + displayName: "Job Backoff Limit" + description: "The number of attempts to try for a successful job outcome" + value: "0" + required: false +objects: +- kind: "CronJob" + apiVersion: "batch/v1" + metadata: + name: "${JOB_NAME}" + labels: + template: "${JOB_NAME}-cronjob" + cronjob: "${JOB_NAME}" + spec: + schedule: "${SCHEDULE}" + concurrencyPolicy: "Forbid" + successfulJobsHistoryLimit: "${{SUCCESS_JOBS_HISTORY_LIMIT}}" + failedJobsHistoryLimit: "${{FAILED_JOBS_HISTORY_LIMIT}}" + jobTemplate: + metadata: + labels: + template: "${JOB_NAME}-job" + cronjob: "${JOB_NAME}" + spec: + backoffLimit: ${{JOB_BACKOFF_LIMIT}} + template: + metadata: + labels: + template: "${JOB_NAME}-job" + cronjob: "${JOB_NAME}" + spec: + containers: + - name: "${JOB_NAME}-cronjob" + image: "${IMAGE_REGISTRY}/${IMAGE_NAMESPACE}/${SOURCE_IMAGE_NAME}:${TAG_NAME}" + # image: backup + command: + - "/bin/bash" + - "-c" + - "mkdir -p /backups/minio-backups-by-cron; rsync -avu --delete /minio-data/ /backups/minio-backups-by-cron" + volumeMounts: + - mountPath: "${BACKUP_DIR}" + name: "backup" + - mountPath: "/minio-data" + name: "minio-data" + env: + - name: BACKUP_DIR + value: "${BACKUP_DIR}/minio-backups-by-cron/" + volumes: + - name: backup + persistentVolumeClaim: + claimName: "${JOB_PERSISTENT_STORAGE_NAME}" + - name: minio-data + persistentVolumeClaim: + claimName: ${MINIO_CLAIM_NAME} + restartPolicy: "Never" + terminationGracePeriodSeconds: 30 + activeDeadlineSeconds: 1600 + dnsPolicy: "ClusterFirst" + serviceAccountName: "${JOB_SERVICE_ACCOUNT}" + serviceAccount: "${JOB_SERVICE_ACCOUNT}" diff --git a/openshift-v4/templates/knp/3-spilo.yaml b/openshift-v4/templates/knp/3-spilo.yaml index 66576aa89..831b4972b 100644 --- a/openshift-v4/templates/knp/3-spilo.yaml +++ b/openshift-v4/templates/knp/3-spilo.yaml @@ -25,6 +25,7 @@ objects: ## Allow tfrs-spilo to accept communications from nagios ## Allow tfrs-spilo to accept communications from backup-container ## Allow tfrs-spilo to accept communications from metabase from cthub + ## Allow tfrs-spilo to accept communications from cron backup podSelector: matchLabels: app.kubernetes.io/instance: tfrs-spilo @@ -85,6 +86,13 @@ objects: ports: - protocol: TCP port: 5432 + - from: + - podSelector: + matchLabels: + cronjob: tfrs-db-backup + ports: + - protocol: TCP + port: 5432 - from: - namespaceSelector: matchLabels: