ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Issue: Persist Generates DB Client Before Pulling Dependencies #7388

Open chathushkaayash opened 1 day ago

chathushkaayash commented 1 day ago

Description

Issue Description

When building a Ballerina project with the persist module, the build process attempts to generate the database client (persist(generate-db-client)) before pulling dependencies. This causes following errors when dependencies like ballerinax/persist.sql are missing, especially on systems or environments without a cache (e.g., Choreo deployments).

Executing Build Tools
        persist(generate-db-client)
ERROR [Ballerina.toml:(1:1,22:1)] unexpected error occurred while generating the client
the model definition file(model.bal) has errors.
ERROR [model.bal:(3:1,3:31)] cannot resolve module ballerinax/persist.sql as sql
ERROR [model.bal:(6:5,6:19)] undefined annotation Generated
ERROR [model.bal:(6:5,6:19)] undefined module sql
ERROR [model.bal:(29:5,29:19)] undefined annotation Generated
ERROR [model.bal:(29:5,29:19)] undefined module sql

Steps to Reproduce

Steps to Reproduce

  1. Clear the Ballerina cache

  2. Create a new Ballerina project:

    • Initialize the project using the following command:
      bal new persist-sample
    • Navigate to the project directory:
      cd persist-sample
  3. Initialize Ballerina Persist:

    • Run the following command to add Persist to the project:
      bal persist init
  4. Add a model.bal file with the following content:

    import ballerina/persist as _;
    import ballerina/time;
    import ballerinax/persist.sql;
    
    type User record {|  
       @sql:Generated  
       readonly int id;  
       string name;  
       string email;  
       string password;  
       string number;  
       string profilePic;  
       string role;  
       string status;  
    
       time:Civil? lastLogin;  
    
       time:Civil createdAt;  
       time:Civil updatedAt;  
       time:Civil? deletedAt;  
    |};
    
  5. Run the build command:

    
    bal build

Version

Ballerina version: 2201.10.2

Environment Details (with versions)

Ballerina version: 2201.10.2 OS: Windows