Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit for EF db seeder #53

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

lizard-boy
Copy link

@lizard-boy lizard-boy commented Oct 19, 2024

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-5985

📔 Objective

Use EF to create CLI for seeding databases for the specific provider

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Greptile Summary

This pull request introduces a new database seeding functionality using Entity Framework for the Bitwarden server project.

  • Added util/DBSeeder/EFDBSeeder.cs with methods to seed users and ciphers using Bogus for fake data generation
  • Created util/DBSeeder/Factories.cs with a DatabaseContextFactory for creating DatabaseContext instances
  • Implemented a CLI in util/EFDBSeederUtility/Program.cs for executing the seeding process
  • Added project files DBSeeder.csproj and EFDBSeederUtility.csproj with necessary dependencies and references
  • Modified bitwarden-server.sln to include the new DBSeeder and EFDBSeederUtility projects

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 file(s) reviewed, 8 comment(s)
Edit PR Review Bot Settings | Greptile

{
private readonly string _connectionString;
private readonly string _databaseProvider;
private readonly ILogger<EFDBSeeder> _logger;
Copy link

Choose a reason for hiding this comment

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

style: ILogger is declared but never used

Comment on lines +33 to +34
var factory = new DatabaseContextFactory();
using (var context = factory.CreateDbContext(new[] { _connectionString }))
Copy link

Choose a reason for hiding this comment

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

logic: DatabaseContextFactory is not using the _databaseProvider. Ensure it's correctly configured for different database types




return true;
Copy link

Choose a reason for hiding this comment

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

logic: This always returns true, even if an exception is thrown. Consider returning false on exceptions

.RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.Name))
.RuleFor(u => u.EmailVerified, f => f.Random.Bool(0.9f))
.RuleFor(u => u.SecurityStamp, f => Guid.NewGuid().ToString())
.RuleFor(u => u.ApiKey, f => Guid.NewGuid().ToString("N").Substring(0, 30))
Copy link

Choose a reason for hiding this comment

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

style: ApiKey generation might not be secure. Consider using a cryptographically secure method

Comment on lines +22 to +23
services.AddDbContext<DatabaseContext>(options =>
options.UseSqlServer(connectionString));
Copy link

Choose a reason for hiding this comment

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

style: This hardcodes SQL Server. Consider using a provider-agnostic approach to support multiple database types.

Comment on lines +20 to +24
var services = new ServiceCollection();
services.AddDataProtection();
services.AddDbContext<DatabaseContext>(options =>
options.UseSqlServer(connectionString));
var serviceProvider = services.BuildServiceProvider();
Copy link

Choose a reason for hiding this comment

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

style: ServiceCollection is created and immediately disposed. Consider passing IServiceProvider as a parameter for better testability and reusability.

public void Execute(

[Operand(Description = "Database provider (mssql, mysql, postgres, sqlite).")] string databaseProvider,
[Operand(Description = "Database connection string.")] string ConnectionString
Copy link

Choose a reason for hiding this comment

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

style: ConnectionString parameter name should be camelCase for consistency

var seeder = new EFDBSeeder(databaseConnectionString, databaseProvider);
bool success;

success = seeder.SeedDatabase(); // Change this line
Copy link

Choose a reason for hiding this comment

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

style: Remove the comment '// Change this line' as it's no longer relevant

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