Skip to content

fix: DB path, import file picker blackout, and sync registry columns#36

Merged
iamvirul merged 6 commits into
masterfrom
fix/db-path-application-support
Jun 25, 2026
Merged

fix: DB path, import file picker blackout, and sync registry columns#36
iamvirul merged 6 commits into
masterfrom
fix/db-path-application-support

Conversation

@iamvirul

@iamvirul iamvirul commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Three fixes: database stored in the wrong directory on macOS, import DB causing a black screen, and MySQL sync failing due to wrong column definitions in the suppliers and customers tables.

Type

  • Bug fix

Changes

  • Move SQLite database from ~/Documents/ to ~/Library/Application Support/lk.getbms.bms/ using LazyDatabase + NativeDatabase.createInBackground() with getApplicationSupportDirectory()
  • Invert Import Database flow: open NSOpenPanel (file picker) first, then show confirmation dialog with selected filename - eliminates the dialog-to-native-panel transition that caused the macOS Metal renderer to go black and become unresponsive
  • _suppliers sync registry: remove credit_limit (does not exist in the Drift Suppliers table), add payment_terms (nullable text) and is_active (integer)
  • _customers sync registry: add missing is_active column to match the Drift schema

Screenshots

N/A - no UI changes (import DB UX order changes but looks the same)

Test plan

  • Hot reloaded and tested manually
  • Checked on Chrome (flutter run -d chrome)
  • No regressions in related screens

Specific checks:

  • Fresh launch: bms_local.sqlite created at ~/Library/Application Support/lk.getbms.bms/bms_local.sqlite, not in ~/Documents/
  • Settings > Import Database: file picker opens immediately without black screen; confirmation dialog shows filename; cancel at either step does nothing; confirm imports data
  • Settings > MySQL sync: suppliers table syncs without no such column: credit_limit error
  • Customers sync includes is_active and credit_limit columns

Related issues

N/A

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Moved the local SQLite database to the OS “Application Support” directory.
    • Fixed the macOS database import flow to prevent black/unresponsive windows.
    • Corrected MySQL synchronization mappings for customer/supplier fields (including is_active and supplier payment fields).
    • Updated the local sync schema for customer/supplier columns to match expected nullability and fields.
  • Improvements

    • Refined database import: file is selected first, and the confirmation dialog shows the selected filename.
    • Added a localized “File” label across supported languages.

iamvirul added 3 commits June 24, 2026 02:56
…tion dialog

- Store bms_local.sqlite in getApplicationSupportDirectory() instead of
  Documents/; drift_flutter defaults to Documents on desktop which is
  wrong for app data. Uses LazyDatabase + NativeDatabase with explicit path.

- Invert import DB flow: open NSOpenPanel first, then show confirmation
  dialog with the selected filename. The previous dialog→NSOpenPanel
  sequence caused the macOS window to go black and become unresponsive
  because NSOpenPanel captured Metal render focus mid-animation.
suppliers: removed credit_limit (does not exist in the Drift schema),
added payment_terms (nullable text) and is_active (integer/bool).

customers: added missing is_active column; kept credit_limit which
exists as creditLimit -> credit_limit in SQLite.
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d532b8e-3c6b-4fc8-abe4-6353319f1f38

📥 Commits

Reviewing files that changed from the base of the PR and between c9055f0 and 111ab71.

📒 Files selected for processing (1)
  • lib/data/database/connection_native.dart
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/data/database/connection_native.dart

📝 Walkthrough

Walkthrough

The PR updates database connection setup, refactors the settings import flow to use a preselected file, corrects sync table mappings for customers and suppliers, and adds a new fileLabel localization string across supported languages.

Changes

Database, import, sync, and labels

Layer / File(s) Summary
Database connection setup
lib/data/database/app_database.dart, lib/data/database/connection_native.dart, lib/data/database/connection_web.dart
Adds platform-specific database connection functions for web and native targets, and changes AppDatabase to use openAppDatabaseConnection().
Sync table mappings
lib/data/sync/sync_tables_registry.dart
Changes the customers sync columns so credit_limit is non-nullable, and changes the suppliers sync columns to remove credit_limit and add payment_terms.
Import flow and labels
lib/providers/settings_provider.dart, lib/features/settings/presentation/settings_screen.dart, lib/l10n/app_*.arb, lib/l10n/app_localizations*.dart, CHANGELOG.md
Refactors the settings import flow to pick a JSON file first, pass the selected PlatformFile into importDatabaseFromJson, update the audit source name, and add fileLabel translations plus changelog entries.

Possibly Related PRs

  • getbms/bms#35: Modifies the same SettingsScreen._importDb import flow that this PR restructures around file selection and confirmation.

Suggested Reviewers

  • hiranyasemindi

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hoppity-hop, the file came first,
Then dialogs sang, and black windows burst.
SQLite found a better home to stay,
While rabbits sorted syncs and labels all day.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main fixes in the pull request.
Description check ✅ Passed The description matches the template and includes summary, type, changes, screenshots, test plan, and related issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/db-path-application-support

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/data/database/app_database.dart`:
- Around line 181-184: Before creating the NativeDatabase in the LazyDatabase
lambda, add a one-time migration check to handle existing users. After obtaining
the directory path and creating the file reference for the new location, check
if a legacy database file exists at the old Documents location
(Documents/bms_local.sqlite). If it exists and the new file does not yet exist,
copy or move the legacy database file from Documents to the new Application
Support location. This ensures existing desktop users retain their data after
the upgrade instead of being booted into a fresh empty database.

In `@lib/data/sync/sync_tables_registry.dart`:
- Line 84: The SyncColumn definitions for is_active are incorrectly using the
_ts timestamp descriptor instead of an integer descriptor, which will cause
wrong serialization/parsing during sync operations. Find both occurrences of
SyncColumn('is_active', _ts) in the sync_tables_registry.dart file and replace
_ts with the appropriate integer descriptor that matches the Drift/MySQL
contract for is_active as an integer flag.

In `@lib/features/settings/presentation/settings_screen.dart`:
- Around line 186-187: The comment on line 186 of the settings_screen.dart file
contains an em-dash character that violates the repository's coding guidelines
for Dart files. Replace the em-dash (`—`) with a regular hyphen (`-`) in the
comment that reads "Open file picker first — avoids the dialog→NSOpenPanel
transition" to comply with the style guide requirement to use hyphens instead of
em-dashes.
- Line 195: The confirmation message in the settings_screen.dart file on line
195 contains a hardcoded English label `'File: '` within the Text widget
content. To maintain internationalization consistency, replace the hardcoded
`'File: '` string with a localized equivalent by accessing `context.l10n`
(similar to how `importDatabaseMessage` is already being localized). You will
need to add a corresponding localization key in your i18n resource files if one
does not already exist (such as `fileLabel` or `filePrefix`), then reference it
in the message construction to ensure all user-facing text is properly
localized.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 44ff4ab8-47d3-47a3-a1dd-4e562e911bde

📥 Commits

Reviewing files that changed from the base of the PR and between a3f066d and 17b5512.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • lib/data/database/app_database.dart
  • lib/data/sync/sync_tables_registry.dart
  • lib/features/settings/presentation/settings_screen.dart
  • lib/providers/settings_provider.dart

Comment thread lib/data/database/app_database.dart Outdated
Comment thread lib/data/sync/sync_tables_registry.dart
Comment thread lib/features/settings/presentation/settings_screen.dart Outdated
Comment thread lib/features/settings/presentation/settings_screen.dart Outdated
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Preview deployed

URL https://getbms.github.io/bms/pr-36/
Commit 02139d6
Status Live

Updates automatically on every push.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/data/database/connection_native.dart`:
- Around line 14-19: The legacy migration in connection_native.dart only copies
the main bms_local.sqlite file, so update the migration logic around the
file.existsSync() block in the native database connection setup to also handle
the SQLite WAL sidecars from the legacy location. Use the existing File handling
with legacy and file to copy bms_local.sqlite-wal and bms_local.sqlite-shm when
they exist, or otherwise checkpoint/flush before moving so no committed changes
are lost during migration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 03ac7db3-ffc3-43d7-ad82-2d762b8b679e

📥 Commits

Reviewing files that changed from the base of the PR and between 7e747bf and c9055f0.

📒 Files selected for processing (3)
  • lib/data/database/app_database.dart
  • lib/data/database/connection_native.dart
  • lib/data/database/connection_web.dart
✅ Files skipped from review due to trivial changes (1)
  • lib/data/database/connection_web.dart

Comment thread lib/data/database/connection_native.dart
@iamvirul iamvirul requested a review from hiranyasemindi June 25, 2026 07:51
@iamvirul iamvirul merged commit fb892b4 into master Jun 25, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants