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

Import pagedata to sites with multiple assignments #586

Open
moz0817 opened this issue Oct 6, 2021 · 5 comments
Open

Import pagedata to sites with multiple assignments #586

moz0817 opened this issue Oct 6, 2021 · 5 comments
Assignees

Comments

@moz0817
Copy link

moz0817 commented Oct 6, 2021

If page (s) are assigned to several schemas, there is a problem with the csv import.
When importing into the first scheme, all data disappears from the other assigned schemes.
If you look in the sqlite tables, you can see that the data from the other schemas have also received a new revision - but without the data being adopted.
Of course, this only affects pages that are updated with the import.

I think an import into schema A should never touch data from schema B.

@grg8
Copy link

grg8 commented Mar 30, 2022

Hi there! Same problem here. I heavily try to create a merging/join from multiple tables to achieve having one huge table containing the information from several tables. Luckily there is the possibility to assign multiple tables to one page. BUT then I realized that I can't import data from csv into one of those tables without losing the other data.

Obviously when data is imported into one table there is another empty row created in the other tables for this page where multiple tables are assigned to. I found kind of a workaround after inspecting the data/meta/struct.sqlite3 file via sqlitebrowser

  1. Exporting ALL schema data assigned to one page as csv, each has a DateTime column "timestamp"
  2. Emptying all the tables
  3. Importing all the tables
  4. At command line (Linux Server):
schema= # enter your schema name here
column= # enter the col number of timestamp column

# "disable" all entries
echo "update data_${schema} set latest = 0 where latest = 1" | sqlite3 struct.sqlite3

# "enable" all entries with timestamp
echo "update data_${schema} set latest = 1 where col${column} <> ''" | sqlite3 struct.sqlite3

I thought: yippie! The entries are displayed in aggregation BUT now i would need to enter the values again that they are shown on pages also.

I am kind of baffled right now how to continue. There is lots of data to import via CSV in my case. Maybe someone could point me to any chance of solving this:

  • Can the workaround be solved without having to click at every value?
  • Is there another way to merge/join multiple tables into one? (structjoin plugin just can join one lookup)
  • Is there any prospect (when) this issue could be solved?
  • Where is the code that causes this behaviour?

Any hint even at one of those questions would be highly welcome!

@moz0817
Copy link
Author

moz0817 commented Mar 30, 2022

My workaround for two schemas was also with sqlite:

  1. dokuwiki: delete all data in both schemas
  2. dokuwiki: import data to the first schema
  3. dokuwiki: import data to the second schemas
  4. sqlite: delete all data in the first schema where latest=1
  5. sqlite: update all data in the first schema with latest=1

@grg8
Copy link

grg8 commented Mar 31, 2022

Thank you sir! Deleting does the trick. With multiple schemas:
4. sqlite: delete all data from each schema where rev is not the oldest

@grg8
Copy link

grg8 commented Apr 1, 2022

Thanks a lot Matthias for your hint! I am not sure how long I would have struggled on this one otherwise...

For the sake of completeness: Here comes my workaround that seems to do the job for multiple schemas assigned to one page ("respective schemas").

  1. server: backup ''data/meta/struct.sqlite3''
  2. dokuwiki: export all data in respective schemas
  3. dokuwiki: delete/clear all data in respective schemas
  4. dokuwiki: import data to respective schemas
  5. sqlite: delete all added data that is not wanted in the respective schemas
  6. sqlite: update all data in the respective schemas with latest=1

ad 5 & 6: When importing data to the empty schema the first entry is the wanted one. When importing data to another schema there is an empty data row added with same ''pid'' but a later ''rev''. The ''rev'' is a Unix timestamp for when the row was created. Therefore, the following SQL syntax deletes all rows of a ''pid'' that are not the oldest one. As I am not into depth of struct plugin nor a SQL programmer this code is at own risk. It can only be fired once, so if something went wrong proceed with point 3.

At Linux server with installed ''sqlite3'' and ''bash'' (at least version 3) package:

db="" # enter the (full) path to `data/meta/struct.sqlite3` file
schema_=(
    # enter respective schemas here separated by a white space character
    # as they are defined in struct plugin (without leading `data_`)
)

for schema in "${schema_[@]}" ; do
    echo "

        DELETE FROM data_${schema}
        WHERE rev NOT IN (
            SELECT MIN(rev)
            FROM data_${schema}
            GROUP BY pid
        ) ;

        UPDATE data_${schema} SET latest = 1 ;

        " | sqlite3 "${db}"
done

Cheers!

@Juergen-aus-Zuendorf
Copy link

Phew, not really a solution for normal users

@annda annda self-assigned this Nov 14, 2023
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