Skip to content

feat: support initial model and tuple loading#171

Open
Adrastopoulos wants to merge 2 commits into
openfga:mainfrom
Adrastopoulos:feat/openfga-initialization
Open

feat: support initial model and tuple loading#171
Adrastopoulos wants to merge 2 commits into
openfga:mainfrom
Adrastopoulos:feat/openfga-initialization

Conversation

@Adrastopoulos

@Adrastopoulos Adrastopoulos commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Adds startup initialization, the OpenFGA analogue of data.sql: when openfga.initialization.mode=embedded, it writes an authorization model (and optional tuples) from configured resource locations. Idempotent (skips if the store already has a model) and fails fast on bad config.

Assumes openfga.store-id is set; auto-creating a store could be a follow-up.

Closes #57.

Adds OpenFGA startup initialization analogous to Spring Boot's
schema.sql/data.sql. When openfga.initialization.mode=embedded, an
OpenFgaInitializer ApplicationRunner writes the configured authorization
model and optional initial tuples into the store at startup, skipping
when a model already exists.

Closes openfga#57
Copilot AI review requested due to automatic review settings June 25, 2026 17:16
@Adrastopoulos Adrastopoulos requested a review from a team as a code owner June 25, 2026 17:16
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Adrastopoulos, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 minutes and 55 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 066d8f28-5a5a-48af-bebe-cc5d2729f5eb

📥 Commits

Reviewing files that changed from the base of the PR and between 558d492 and b02d091.

📒 Files selected for processing (8)
  • build.gradle
  • src/main/java/dev/openfga/autoconfigure/OpenFgaAutoConfiguration.java
  • src/main/java/dev/openfga/autoconfigure/OpenFgaInitializer.java
  • src/main/java/dev/openfga/autoconfigure/OpenFgaProperties.java
  • src/test/java/dev/openfga/autoconfigure/OpenFgaAutoConfigurationTests.java
  • src/test/java/dev/openfga/autoconfigure/OpenFgaInitializerTest.java
  • src/test/resources/fga/model.json
  • src/test/resources/fga/tuples.json
✨ 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.

Copilot AI 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.

Pull request overview

Adds optional OpenFGA startup initialization (model + optional tuples) driven by new openfga.initialization.* properties, similar in spirit to Spring Boot SQL initialization.

Changes:

  • Introduces OpenFgaInitializer (ApplicationRunner) to write an authorization model and optional tuples at startup when mode=embedded.
  • Extends OpenFgaProperties with initialization configuration + validation for required model-location in embedded mode.
  • Wires initializer creation into OpenFgaAutoConfiguration and adds ApplicationContextRunner tests plus JSON fixtures.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/java/dev/openfga/autoconfigure/OpenFgaInitializer.java New startup initializer that checks for an existing model, writes model, then optionally writes tuples.
src/main/java/dev/openfga/autoconfigure/OpenFgaAutoConfiguration.java Conditionally registers OpenFgaInitializer bean when openfga.initialization.mode=embedded.
src/main/java/dev/openfga/autoconfigure/OpenFgaProperties.java Adds initialization config block and validates model-location for embedded mode.
src/test/java/dev/openfga/autoconfigure/OpenFgaAutoConfigurationTests.java Adds coverage for initializer bean conditional creation and validation failure case.
src/test/resources/fga/model.json Test fixture for an example authorization model payload.
src/test/resources/fga/tuples.json Test fixture for an example initial tuples payload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/dev/openfga/autoconfigure/OpenFgaInitializer.java Outdated
Comment thread src/main/java/dev/openfga/autoconfigure/OpenFgaProperties.java
Comment thread src/main/java/dev/openfga/autoconfigure/OpenFgaInitializer.java

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.

Comment on lines +367 to +372
if (initialization != null
&& initialization.getMode() == InitializationMode.EMBEDDED
&& !StringUtils.hasText(initialization.getModelLocation())) {
throw new IllegalStateException(
"initialization.model-location must be set when initialization.mode is 'EMBEDDED'");
}
Comment on lines +64 to +66
private boolean authorizationModelExists() throws Exception {
return fgaClient.readLatestAuthorizationModel().get().getAuthorizationModel() != null;
}
Comment on lines +75 to +76
String authorizationModelId =
fgaClient.writeAuthorizationModel(request).get().getAuthorizationModelId();
Comment on lines +94 to +100
fgaClient
.write(
request,
new ClientWriteOptions()
.authorizationModelId(authorizationModelId)
.disableTransactions(true))
.get();
Comment on lines +94 to +97
stubResource("classpath:fga/tuples.json", "[]".getBytes());
when(objectMapper.readValue("{}".getBytes(), WriteAuthorizationModelRequest.class))
.thenReturn(new WriteAuthorizationModelRequest());
when(objectMapper.readValue("[]".getBytes(), ClientWriteRequest.class)).thenReturn(new ClientWriteRequest());
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.

Add Support for OpenFGA Initialization

2 participants