About data management of anvil-app-server
Preface h2>
It's nice to be able to run the app on ʻanvil-app-server`, but let's run the `News Aggregater` app created on the [Anvil](https://anvil.works/) site. Even so, it doesn't seem to move smoothly. .. ..
I did some research.
Premise h4>
--You have already created the [News Aggregator](https://anvil.works/learn/tutorials/database-backed-apps) app in Anvil.
Environment h4>
--Ubuntu 20.04 LTS Japanese Remix
--Hyper-V Manager 10.0.18362.1
- anvil-app-server v1.1
Download and run the News Aggregator app h2>
Once you've created your app, you can download it from `View history` with the` git clone` command.
Click "View history"
Click "Clone with Git"
Copy the line "git clone ssh: // ~" and execute it with the command.
git clone ssh://[email protected]:2222/324IEWAMVBYU2Y77.git News_Aggregater
XXXX
is the email address of the account registered on the Anvil site.
- If you have enabled two-factor authentication, you will have to use the SSH public key, so if you are using it, temporarily remove the two-step verification. I think it will be easier if you register a public key in Git.
Launch the application with ʻanvil-app-server`.
anvil-app-server --app News_Aggregater
Access http: // localhost: 3030
with a browser.
Suddenly an error.
Problems h2>
In the News Aggrigator app, the article `category` is registered in advance in the` categories` table and selected from there, but since the app does not contain table data, "empty data" Will result in an error.
Access PostgreSQL of anvil-app-server with pgadmin4 h2>
ʻAnvil-app-server` contains its own PostgreSQL server, so access it.
- Username : postgres
--Password: (directory where anvil-app-server was executed) /.anvi-data/postgres.password
--Port: (directory where anvil-app-server was executed) /.anvi-data/db/postmaster.opts
However, apparently, there is neither a ʻarticles table nor a
categories` table that the app should need.
For the time being, if you look at the contents of the existing table, you will find the information of the table created by the application in the ʻapp_storage_tables` table.
Also, looking at creating data using the todo app that can be created with the create-anvil-app
command, it turns out that data has been added to the ʻapp_storage_data` table.
What does that mean? H2>
From the above,
--Table information used by the app is stored in JSON format in the ʻapp_storage_tables table. --When accessing data from the app, access the JSON format data in the ʻapp_storage_data
table based on the information in the ʻapp_storage_tables` table.
From the point of view that the data layer and the logic layer can be matched no matter what app you make, it is not unthinkable to use a meta table, but it is a mechanism that frustrates the hearts of amateurs.
Others h2>
When I was able to see what kind of data management it was, I went back to Anvil's site and downloaded the data in order to import the data.
However, the downloaded data cannot be easily imported.
In the case of the `categories` table of News Aggrigator this time,
ID |
name |
[65114][57547127] |
entertainment |
[65114][57547131] |
business |
[65114][57547132] |
travel |
[65114][57547134] |
sport |
You have to write the JSON format data in a form that is consistent with the meta table of the local DB.
- The ID column is "probably" the information when the data is on the server hosted by Anvil, so it doesn't seem to make much sense in the local DB. Intuitively, I think it's about table ID and row ID.