Skip to content

set up Drift database with local data models#48

Open
4555jan wants to merge 15 commits into
StabilityNexus:devfrom
4555jan:feat/week1-drift-database-setup
Open

set up Drift database with local data models#48
4555jan wants to merge 15 commits into
StabilityNexus:devfrom
4555jan:feat/week1-drift-database-setup

Conversation

@4555jan

@4555jan 4555jan commented May 24, 2026

Copy link
Copy Markdown

Addressed Issues:

Fixes #47

Screenshots/Recordings:

No UI changes in this PR — this is a database layer setup (Drift table definitions and AppDatabase class). No before/after screenshots applicable.

Additional Notes:

This PR sets up the Drift local database foundation for Zplit. It includes the AppDatabase class and five table definitions: UsersTable, GroupsTable, TransactionsTable, BalancesTable, and WalletDetailsTable. database initialization will be wired up in a follow-up PR.
The generated file app_database.g.dart is a build_runner output and is excluded from this PR.

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 48dfb47c-e63a-41a9-a865-02d7aa074e6e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@4555jan 4555jan added the gsoc label May 24, 2026
@4555jan 4555jan requested a review from M4dhav May 25, 2026 20:55
@4555jan

4555jan commented May 26, 2026

Copy link
Copy Markdown
Author

@M4dhav is this correct ? or it requires some changes ?

…th upsert functions and removed wallet from the db
@4555jan

4555jan commented May 27, 2026

Copy link
Copy Markdown
Author

@M4dhav i removed the insert functions as from as well i added upsert which basically does the same thing is that ok? and i did other changes as well

@Mayank4352 Mayank4352 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Kindly make the requested changes, also if have any questions or suggestions feel free to comment

const _uuid = Uuid();

@DriftDatabase(
tables: [UsersTable, TransactionsTable, BalancesTable, GroupsTable],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Scope (issue #47) lists 5 tables it's missing WalletDetailsTable

@4555jan 4555jan Jun 3, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

actually i discussed with the mentors and turns out we no longer need that table and i also modified the initial issue template

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay

tables: [UsersTable, TransactionsTable, BalancesTable, GroupsTable],
daos: [TransactionsDao, GroupsDao, UsersDao, BalancesDao],
)
class AppDatabase extends _$AppDatabase {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SQLite doesn't enforce foreign keys by default, so the .references() in transactions and balances are currently non-functional

class GroupsTable extends Table {
TextColumn get id => text().clientDefault(() => _uuid.v4())();
TextColumn get name => text()();
// storing member public keys as comma separated string

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Storing member keys as a comma-separated string bypasses many of the benefits of a relational database. It removes foreign key enforcement (deleted users can leave dangling references)

TextColumn get description => text().nullable()();

@override
String get tableName => 'groups_table';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tiny consistency note: this one is 'groups_table' while the others are users, transactions, balances


const _uuid = Uuid();

class GroupsTable extends Table {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maintain a reference for transaction table to access the transactions in groups, also using a simple FK here will not be a good approach since one group can have multiple transactions

return into(balancesTable).insertOnConflictUpdate(balance);
}

Future<int> deletebalaces(String userPublicKey) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

there is a typo also use lower camel case

return query.getSingleOrNull();
}

Future<void> upsert(UsersTableCompanion user) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use lower camel case

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

upsert is already in lower camel case could you clarify what you'd like changed here

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i think this was marked by mistake

Comment thread lib/core/database/daos/users_dao.dart Outdated
return into(usersTable).insertOnConflictUpdate(user);
}

Future<int> deleteuser(String publicKey) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use lower camel case

TextColumn get fromUserPublicKey =>
text().references(UsersTable, #publicKey)();
TextColumn get toUserPublicKey => text().references(UsersTable, #publicKey)();
IntColumn get amount => integer()();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can use int64, keeping large crypto values in mind

@DecodeX15

Copy link
Copy Markdown

@4555jan i have reviewed your pr all things pointed by mayank already, so just fix that and overall it's LGTM

Comment thread lib/core/database/daos/groups_dao.dart Outdated
return into(groupsTable).insertOnConflictUpdate(group);
}

Future<int> deletegroup(String id) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

use lower camel case


class GroupsTable extends Table {
TextColumn get id => text().clientDefault(() => _uuid.v4())();
TextColumn get name => text()();

@Mayank4352 Mayank4352 Jun 5, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

it's still just a string relabeled as set, so no dupe protection ("abc,def,abc" is allowed), no FK integrity (foreign keys can't reach inside a CSV, so the PRAGMA foreign_keys = ON doesn't protect membership), and "which groups is user X in?" are still unindexed and gets false-matches on substrings like (alice matches alice99).

Standard fix is a join table, one row per membership, but you can look for better solution as well

Comment thread lib/core/database/app_database.dart Outdated
)
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(_openConnection());
AppDatabase.forTesting(QueryExecutor executor) : super(executor);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This can be AppDatabase.forTesting(super.executor); instead of AppDatabase.forTesting(QueryExecutor executor) : super(executor);
it'll raise analyser problem

@4555jan

4555jan commented Jun 7, 2026

Copy link
Copy Markdown
Author

@M4dhav please review it does everything seems fine ?

@M4dhav M4dhav linked an issue Jun 8, 2026 that may be closed by this pull request
2 tasks
@M4dhav M4dhav added the enhancement New feature or request label Jun 8, 2026

@M4dhav M4dhav 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.

Make sure the generated files go into a separate folder to keep the working directory clean. Check @Mayank4352 's build.yaml in Resonate.

@4555jan

4555jan commented Jun 12, 2026

Copy link
Copy Markdown
Author

@M4dhav i did requested changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request gsoc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: -Set up Drift database with local data models

4 participants