diff --git a/brewman/brewman/routers/rebase.py b/brewman/brewman/routers/rebase.py index 06510624..25c15bd4 100644 --- a/brewman/brewman/routers/rebase.py +++ b/brewman/brewman/routers/rebase.py @@ -209,29 +209,52 @@ def delete_data(date_: date, vouchers: List[Voucher], db: Session) -> None: sub_voucher = aliased(Voucher) sub_query = select(sub_voucher.id).where(sub_voucher.date < date_).subquery() - db.execute(delete(Inventory).where(Inventory.voucher_id.in_(sub_query))) - db.execute(delete(EmployeeBenefit).where(EmployeeBenefit.voucher_id.in_(sub_query))) - db.execute(delete(Incentive).where(Incentive.voucher_id.in_(sub_query))) - db.execute(delete(Journal).where(and_(Journal.voucher_id.in_(sub_query), ~Journal.voucher_id.in_(vouchers)))) db.execute( - delete(DbImage).where( + delete(Inventory).where(Inventory.voucher_id.in_(sub_query)).execution_options(synchronize_session=False) + ) + db.execute( + delete(EmployeeBenefit) + .where(EmployeeBenefit.voucher_id.in_(sub_query)) + .execution_options(synchronize_session=False) + ) + db.execute( + delete(Incentive).where(Incentive.voucher_id.in_(sub_query)).execution_options(synchronize_session=False) + ) + db.execute( + delete(Journal) + .where(and_(Journal.voucher_id.in_(sub_query), ~Journal.voucher_id.in_(vouchers))) + .execution_options(synchronize_session=False) + ) + db.execute( + delete(DbImage) + .where( and_( DbImage.resource_type == "voucher", DbImage.resource_id.in_(sub_query), ~DbImage.resource_id.in_(vouchers), ) ) + .execution_options(synchronize_session=False) + ) + db.execute( + delete(Voucher) + .where(Voucher.date < date_, ~Voucher.id.in_(vouchers)) + .execution_options(synchronize_session=False) ) - db.execute(delete(Voucher).where(Voucher.date < date_, ~Voucher.id.in_(vouchers))) def cleanup_lint(date_: date, db: Session) -> None: # Insert executes on the end so keep list of batches and journals - db.execute(delete(Batch).where(~Batch.id.in_(select(distinct(Inventory.batch_id)).subquery()))) - db.execute(delete(Fingerprint).where(Fingerprint.date < date_)) - db.execute(delete(Attendance).where(Attendance.date < date_)) db.execute( - delete(Employee).where( + delete(Batch) + .where(~Batch.id.in_(select(distinct(Inventory.batch_id)).subquery())) + .execution_options(synchronize_session=False) + ) + db.execute(delete(Fingerprint).where(Fingerprint.date < date_).execution_options(synchronize_session=False)) + db.execute(delete(Attendance).where(Attendance.date < date_).execution_options(synchronize_session=False)) + db.execute( + delete(Employee) + .where( and_( ~Employee.id.in_(select(distinct(Journal.account_id)).subquery()), ~Employee.id.in_(select(distinct(Fingerprint.employee_id)).subquery()), @@ -248,22 +271,27 @@ def cleanup_lint(date_: date, db: Session) -> None: Employee.leaving_date < date_, ) ) + .execution_options(synchronize_session=False) ) db.execute( - delete(AccountBase).where( + delete(AccountBase) + .where( and_( ~AccountBase.id.in_(select(Employee.id).subquery()), AccountBase.account_type == Employee.__mapper_args__["polymorphic_identity"], ) ) + .execution_options(synchronize_session=False) ) db.execute( - delete(Account).where( + delete(Account) + .where( and_( ~Account.id.in_(select(distinct(Journal.account_id)).subquery()), Account.is_fixture == False, # noqa: E712 - Account.is_starred == False, + Account.is_starred == False, # noqa: E712 Account.account_type == Account.__mapper_args__["polymorphic_identity"], ) ) + .execution_options(synchronize_session=False) ) diff --git a/brewman/pyproject.toml b/brewman/pyproject.toml index f1e3bd30..bc758905 100644 --- a/brewman/pyproject.toml +++ b/brewman/pyproject.toml @@ -5,9 +5,9 @@ description = "Accounting plus inventory management for a restaurant." authors = ["tanshu "] [tool.poetry.dependencies] -python = "^3.8" -uvicorn = {extras = ["standard"], version = "^0.15.0"} -fastapi = "^0.70.1" +python = "^3.10" +uvicorn = {extras = ["standard"], version = "^0.17.6"} +fastapi = "^0.76.0" python-jose = {extras = ["cryptography"], version = "^3.3.0"} passlib = {extras = ["bcrypt"], version = "^1.7.4"} psycopg2-binary = "^2.9.2" @@ -16,16 +16,16 @@ python-multipart = "^0.0.5" PyJWT = "^2.3.0" alembic = "^1.7.5" itsdangerous = "^2.0.1" -python-dotenv = "^0.19.2" +python-dotenv = "^0.20.0" pydantic = {extras = ["dotenv"], version = "^1.8.2"} -starlette = "^0.16.0" +starlette = "^0.18.0" [tool.poetry.dev-dependencies] flake8 = "^4.0.1" -black = "^21.10b0" +black = "^22.3.0" isort = {extras = ["toml"], version = "^5.10.0"} pre-commit = "^2.15.0" -mypy = "^0.910" +mypy = "^0.950" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/deploy.sh b/deploy.sh index 0e77634b..90b6a3c4 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -set -e - +set -euo pipefail parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P ) cd "$parent_path" || exit -#./lint.sh + +./lint.sh if [ 1 -eq "$#" ] then @@ -25,6 +25,12 @@ curl --silent 'https://git.tanshu.com/tanshu/brewman/raw/tag/latest/brewman/pypr cd "$parent_path/docker/app" || exit docker build --tag brewman:latest . +if [ 1 -eq "$#" ] +then + docker tag brewman:latest "$1" +else + echo "No version bump" +fi cd "$parent_path/docker" || exit docker save brewman:latest | bzip2 | pv | ssh vancity 'bunzip2 | sudo docker load' ansible-playbook --limit vancity playbook-exp.yml diff --git a/docker/app/Dockerfile b/docker/app/Dockerfile index 71b30b4b..148eb5e1 100644 --- a/docker/app/Dockerfile +++ b/docker/app/Dockerfile @@ -13,7 +13,7 @@ RUN mv /node_modules /app/overlord/ \ && /app/overlord/node_modules/.bin/ng build -FROM python:3.9 +FROM python:3.10 LABEL maintainer="Amritanshu " COPY pyproject.toml /app/pyproject.toml diff --git a/docker/files/.env-acc b/docker/files/.env-acc index 4ae239f8..b383c999 100644 --- a/docker/files/.env-acc +++ b/docker/files/.env-acc @@ -2,7 +2,7 @@ HOST=0.0.0.0 PORT=80 LOG_LEVEL=WARN DEBUG=false -SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@db:5432/acc +SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@172.26.5.85:5432/acc MODULE_NAME=brewman.main PROJECT_NAME=brewman POSTGRES_SERVER=db diff --git a/docker/files/.env-exp b/docker/files/.env-exp index a7bfc0bf..868ab8fc 100644 --- a/docker/files/.env-exp +++ b/docker/files/.env-exp @@ -2,7 +2,7 @@ HOST=0.0.0.0 PORT=80 LOG_LEVEL=WARN DEBUG=false -SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@db:5432/exp +SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@172.26.5.85:5432/exp MODULE_NAME=brewman.main PROJECT_NAME=brewman POSTGRES_SERVER=db diff --git a/docker/files/.env-hops b/docker/files/.env-hops index 94a75aee..ec765483 100644 --- a/docker/files/.env-hops +++ b/docker/files/.env-hops @@ -2,7 +2,7 @@ HOST=0.0.0.0 PORT=80 LOG_LEVEL=WARN DEBUG=false -SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@db:5432/hops +SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@172.26.5.85:5432/hops MODULE_NAME=brewman.main PROJECT_NAME=brewman POSTGRES_SERVER=db diff --git a/docker/files/.env-mhl b/docker/files/.env-mhl index b72da50e..cfbdcef4 100644 --- a/docker/files/.env-mhl +++ b/docker/files/.env-mhl @@ -2,7 +2,7 @@ HOST=0.0.0.0 PORT=80 LOG_LEVEL=WARN DEBUG=false -SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@db:5432/mhl +SQLALCHEMY_DATABASE_URI=postgresql://postgres:123456@172.26.5.85:5432/mhl MODULE_NAME=brewman.main PROJECT_NAME=brewman POSTGRES_SERVER=db diff --git a/docker/files/nginx.conf.j2 b/docker/files/nginx.conf.j2 index 64ed0041..42b06ef5 100644 --- a/docker/files/nginx.conf.j2 +++ b/docker/files/nginx.conf.j2 @@ -31,7 +31,12 @@ server { proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://localhost:{{ host_port }}; } - location /db-image { + location /fingerprint-report { + proxy_set_header Host $host:$server_port; + proxy_set_header X-Scheme $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_pass http://localhost:{{ host_port }}; + } location /db-image { proxy_set_header Host $host:$server_port; proxy_set_header X-Scheme $scheme; proxy_set_header X-Forwarded-For $remote_addr; diff --git a/docker/playbook-acc.yml b/docker/playbook-acc.yml index cf085dc6..b459f236 100755 --- a/docker/playbook-acc.yml +++ b/docker/playbook-acc.yml @@ -33,8 +33,6 @@ state: started restart_policy: "unless-stopped" env_file: "/var/lib/{{ host_directory }}/.env" - links: - - "postgres:db" published_ports: - "127.0.0.1:{{ host_port }}:80" volumes: diff --git a/docker/playbook-exp.yml b/docker/playbook-exp.yml index c178d46d..a9437e80 100755 --- a/docker/playbook-exp.yml +++ b/docker/playbook-exp.yml @@ -33,8 +33,6 @@ state: started restart_policy: "unless-stopped" env_file: "/var/lib/{{ host_directory }}/.env" - links: - - "postgres:db" published_ports: - "127.0.0.1:{{ host_port }}:80" volumes: diff --git a/docker/playbook-hops.yml b/docker/playbook-hops.yml index cbb4300b..5733fa1b 100755 --- a/docker/playbook-hops.yml +++ b/docker/playbook-hops.yml @@ -33,8 +33,6 @@ state: started restart_policy: "unless-stopped" env_file: "/var/lib/{{ host_directory }}/.env" - links: - - "postgres:db" published_ports: - "127.0.0.1:{{ host_port }}:80" volumes: diff --git a/docker/playbook-mhl.yml b/docker/playbook-mhl.yml index 01d38937..dec9f3ee 100755 --- a/docker/playbook-mhl.yml +++ b/docker/playbook-mhl.yml @@ -33,8 +33,6 @@ state: started restart_policy: "unless-stopped" env_file: "/var/lib/{{ host_directory }}/.env" - links: - - "postgres:db" published_ports: - "127.0.0.1:{{ host_port }}:80" volumes: diff --git a/lint.sh b/lint.sh index 7b0dc82a..1bbf89e3 100755 --- a/lint.sh +++ b/lint.sh @@ -1,9 +1,13 @@ #!/usr/bin/env bash +set -eEu -o pipefail +shopt -s extdebug +IFS=$'\n\t' + parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P ) cd "$parent_path/overlord" || exit npx prettier --write src/app npx ng lint --fix cd "$parent_path/brewman" || exit -isort brewman -black brewman -flake8 brewman +poetry run isort brewman +poetry run black brewman +poetry run flake8 brewman diff --git a/overlord/.gitignore b/overlord/.gitignore index de51f68a..105c00f2 100644 --- a/overlord/.gitignore +++ b/overlord/.gitignore @@ -31,6 +31,7 @@ chrome-profiler-events*.json .history/* # misc +/.angular/cache /.sass-cache /connect.lock /coverage diff --git a/overlord/package.json b/overlord/package.json index e1585249..63970469 100644 --- a/overlord/package.json +++ b/overlord/package.json @@ -14,46 +14,46 @@ }, "private": true, "dependencies": { - "@angular/animations": "^12.2.13", - "@angular/cdk": "^12.2.12", - "@angular/common": "^12.2.13", - "@angular/compiler": "^12.2.13", - "@angular/core": "^12.2.13", - "@angular/flex-layout": "^12.0.0-beta.35", - "@angular/forms": "^12.2.13", - "@angular/material": "^12.2.12", - "@angular/material-moment-adapter": "^12.2.12", - "@angular/platform-browser": "^12.2.13", - "@angular/platform-browser-dynamic": "^12.2.13", - "@angular/router": "^12.2.13", - "@ngx-loading-bar/core": "^5.1.2", - "@ngx-loading-bar/http-client": "^5.1.2", - "@ngx-loading-bar/router": "^5.1.2", - "@types/mousetrap": "1.6.8", - "angular2-hotkeys": "^2.4.0", - "mathjs": "^10.0.0", - "moment": "^2.29.1", + "@angular/animations": "^13.3.6", + "@angular/cdk": "^13.3.6", + "@angular/common": "^13.3.6", + "@angular/compiler": "^13.3.6", + "@angular/core": "^13.3.6", + "@angular/flex-layout": "^13.0.0-beta.38", + "@angular/forms": "^13.3.6", + "@angular/material": "^13.3.6", + "@angular/material-moment-adapter": "^13.3.6", + "@angular/platform-browser": "^13.3.6", + "@angular/platform-browser-dynamic": "^13.3.6", + "@angular/router": "^13.3.6", + "@ngx-loading-bar/core": "^6.0.2", + "@ngx-loading-bar/http-client": "^6.0.2", + "@ngx-loading-bar/router": "^6.0.2", + "@types/mousetrap": "1.6.9", + "angular2-hotkeys": "^13.1.0", + "mathjs": "^10.5.2", + "moment": "^2.29.3", "rxjs": "^6.6.7", "tslib": "^2.1.0", "zone.js": "~0.11.4" }, "devDependencies": { - "@angular-devkit/build-angular": "^12.2.13", - "@angular-eslint/builder": "^12.6.1", - "@angular-eslint/eslint-plugin": "^12.6.1", - "@angular-eslint/eslint-plugin-template": "^12.6.1", - "@angular-eslint/schematics": "^12.6.1", - "@angular-eslint/template-parser": "^12.6.1", - "@angular/cli": "^12.2.13", - "@angular/compiler-cli": "^12.2.13", - "@angular/language-service": "^12.2.13", + "@angular-devkit/build-angular": "^13.3.5", + "@angular-eslint/builder": "^13.2.1", + "@angular-eslint/eslint-plugin": "^13.2.1", + "@angular-eslint/eslint-plugin-template": "^13.2.1", + "@angular-eslint/schematics": "^13.2.1", + "@angular-eslint/template-parser": "^13.2.1", + "@angular/cli": "^13.3.5", + "@angular/compiler-cli": "^13.3.6", + "@angular/language-service": "^13.3.6", "@types/jasmine": "~3.7.4", - "@types/node": "^16.11.6", - "@typescript-eslint/eslint-plugin": "4.28.2", - "@typescript-eslint/parser": "4.28.2", - "eslint": "^7.26.0", - "eslint-plugin-import": "^2.25.2", - "husky": "^7.0.4", + "@types/node": "^17.0.31", + "@typescript-eslint/eslint-plugin": "5.23.0", + "@typescript-eslint/parser": "5.23.0", + "eslint": "^8.2.0", + "eslint-plugin-import": "2.26.0", + "husky": "^8.0.1", "jasmine-core": "~3.8.0", "jasmine-spec-reporter": "7.0.0", "karma": "^6.3.2", @@ -61,11 +61,11 @@ "karma-coverage": "~2.0.3", "karma-jasmine": "~4.0.1", "karma-jasmine-html-reporter": "^1.6.0", - "lint-staged": "^11.2.6", - "prettier": "^2.4.1", + "lint-staged": "^12.4.1", + "prettier": "^2.6.2", "standard-version": "^9.3.2", "ts-node": "^9.1.1", - "typescript": "~4.2.4" + "typescript": "~4.6.4" }, "husky": { "hooks": { diff --git a/overlord/src/polyfills.ts b/overlord/src/polyfills.ts index 373f538a..dcd18eac 100644 --- a/overlord/src/polyfills.ts +++ b/overlord/src/polyfills.ts @@ -18,18 +18,6 @@ * BROWSER POLYFILLS */ -/** - * IE11 requires the following for NgClass support on SVG elements - */ -// import 'classlist.js'; // Run `npm install --save classlist.js`. - -/** - * Web Animations `@angular/platform-browser/animations` - * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. - * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). - */ -// import 'web-animations-js'; // Run `npm install --save web-animations-js`. - /** * By default, zone.js will patch all possible macroTask and DomEvents * user can disable parts of macroTask/DomEvents patch by setting following flags diff --git a/overlord/src/test.ts b/overlord/src/test.ts index a0e80c3a..8e0cae8f 100644 --- a/overlord/src/test.ts +++ b/overlord/src/test.ts @@ -19,7 +19,9 @@ declare const require: { }; // First, initialize the Angular testing environment. -getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); +getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { + teardown: { destroyAfterEach: false } +}); // Then we find all the tests. const context = require.context('./', true, /\.spec\.ts$/); // And load the modules.