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

Initialize two local data sources simultaneously #1316

Open
tklein1801 opened this issue Oct 2, 2024 · 10 comments
Open

Initialize two local data sources simultaneously #1316

tklein1801 opened this issue Oct 2, 2024 · 10 comments
Assignees

Comments

@tklein1801
Copy link

Hi, I would like to know how I can specify that only one data source is loaded, so that the test only loads the data from test/data and during development only the data from db/data and both can run smoothly.
The documentation under Location of CSV Files only describes the paths where I can create files to load them, but not how I can ignore certain paths, otherwise the following error occurs when starting my application or running my tests:
the following error occurs...

SqliteError: in cds.deploy(): ENTITY_ALREADY_EXISTS
Query {
  INSERT: {
    into: { ref: [ 'sap.common.Currencies' ] },
    columns: [ 'name', 'descr', 'code', 'symbol', 'minorUnit' ],
    rows: [
      [ 'Euro', 'European Euro', 'EUR', '€', '2' ],
      [ 'US Dollar', 'United States Dollar', 'USD', '$', '2' ]
    ]
  }
}
@renejeglinsky
Copy link
Contributor

Hi @tklein1801 ,
please excuse my late reaction and thank you for opening this issue.

@LotharBender would you be able to answer this question?

@LotharBender
Copy link
Contributor

LotharBender commented Oct 15, 2024

Hi @tklein1801 ,
according to Location of CSV Files you have a Java application - is this correct?

Everything under db/data is by default considered for production as well as for local development scenarios.

  • CSV files shared by both scenarios can be added to this folder.
  • CSV files used for local test runs have to moved to the folder test/data
  • CSV files used for production can either be moved to:
    • the folder db/src/**as its entire contents gets deployed to the HANA database. If going for this approach you also have to include the corresponding .hdbtabledata files which are normally generated by the HANA build plugin at location db/src/gen/data/*. Thus you can copy the corresponding files from there and make them source files of your project.
      The advantage of this solution is that you can customize the .hdbtabledata files if required (e.g. adding a custom include_filter setting if you need to mix initial and customer data in one table). The disadvantage is that you have to maintain them.

    • or to some other data subfolder next to CDS model content of your application as described in the Capire documentation. The idea is to define a new profile specific cds model folder (e.g. db/dataHana). This folder has to contain some dummy cds model file, e.g. index.cds. The file must not be empty – adding a namespace declaration is sufficient. Now, configure this model location in some dummy cds service (e.g. dataHanaSrv) using the [production] profile:

      "cds": {
        "requires": {
          "[production]": {
            "dataHanaSrv ": { "model": "dataHana" }
           }
        }
      }
      

      As a consequence cds build –production will add the model folder dataHana while cds deploy will not as the development profile is used by default. You can check the cds build logs for the hana build task.

Best, Lothar

@tklein1801
Copy link
Author

Hi @LotharBender, thank you for your quick reply. I probably should have come up with the idea of the profile myself.

@LotharBender
Copy link
Contributor

LotharBender commented Oct 16, 2024

@renejeglinsky - should I try to merge #1316 (comment) into location of csv files?

@renejeglinsky
Copy link
Contributor

Thanks @LotharBender ! Let's at least give it a try, ok?

@LotharBender
Copy link
Contributor

Thanks @LotharBender ! Let's at least give it a try, ok?

@renejeglinsky - you can review #1349

@mathewzile
Copy link

is the location test/data not supported for hana deployments? i could never get it to be included for non-production (cds build --for hana, cds deploy --to hana) and had to resort to run scripts to move files from test/data to db/csv prior to mbt build

quick setup and cds build --for hana shows that WithTestData.csv under test\data does not get generated into hdbtabledata:
image

@LotharBender
Copy link
Contributor

LotharBender commented Oct 16, 2024

@mathewzile - you can use the profile based approach described in the comment above instead of copying CSV files. Simply add a index.cds file with some dummy content to the test folder and the following cds configuration:

  "requires": {
    "[test]": {
      "testData": { "model": "test" },
    },
    . . .    

cds build --profile production,test will generated hdbtabledata files for the CSV files contained in test/data.

@mathewzile
Copy link

@LotharBender thanks for the suggestion, but maybe the docs should add a note that loading from test/data is not supported for hana deployments without this profile method? Currently it states “Deployed… if not in production“ which might imply that it is automatically included in profiles other than production

i would hope that this becomes a feature instead though

@LotharBender
Copy link
Contributor

LotharBender commented Oct 16, 2024

@mathewzile - we already discussed a more flexible test profile based solution that works out of the box - stay tuned :)

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

No branches or pull requests

4 participants