Restore db data

hi there,

quite a while ago I threw together a modest linguistic rails app demonstrating use of Russian 4-letter words in action based on ruby 2.3.3 which was deployed and worked online OK until the hosting company upgraded their platform to ruby 2.5.5 which broke dependencies and stopped the app.

So I copied the working app (2.3.3) to a repository on the GitHub deciding to look to it later. Then a bundle of concurrent circumstances brought about the aforementioned stretch of time to postpone the fulfilling of my decision and now I’ve run in a number of problems.

Firstly, my proficiency at RoR nosedived drastically. Secondly, the once-working-and-now-brought-back-to-life app shows blank tables which once upon a time had up to 200 rows.

My question is if it is possible to restore the data from the db folder containing:

  • bus@debian:~$ cd mat/maht/db && ls

  • development.sqlite3 migrate schema.rb seeds.rb

  • bus@debian:~/mat/maht/db$ ls migrate

  • 20180529053331_create_w0words.rb 20180529053436_create_w2words.rb

  • 20180529053421_create_w1words.rb

and/or using any other piece of the app a helper would consider needed.

Yours`

sehrguey

Are you trying to recover the database structure only, or also the content? If it’s only the structure should be able to rebuild it by rails db:migrate on a fresh database. Then, run rails db:seed if you have a seed file.

If you’re also looking to restore old content you will have to find a backup of the database. It looks like you’re using sql lite, so the file should be in /db/development.sqlite3. If you have the file in the correct place your Rails should see it as long as the config files are in order.

I don’t care for the database structure, entries to the 3 content tables is all I’m looking for. The /db/development.sqlite3 is in place but /db/seeds.rb contains only entries for 2 of the 3 mentioned tables as checked with the text editor. How about that?

Yours` sehrguey

The database structure is not optional. You have to have the structure to get the data in place. I’m afraid I can’t help with missing data.

You could look for a tool to view the contents of the .sqlite3 file (such as the DB tool I have in IntelliJ IDEA, cousin of RubyMine) and export the data to an SQL file or import it into your database in another manner (after having rebuilt the schema as appropriate).

1 Like

Yep, there are tools that will let you view the contents of /db/<env>.sqlite3. If you Google “sqlite3 GUI” this is the first result: https://sqlitebrowser.org/

Lots of thanks Sébastien and Blaine I installed sqlitebrowser which showed 0 entries in the data containing tables in /db/development.sqlite3 so turned to my repository at GitHub it was downloaded from a week before and… there IS NOT that file at all. Hmm. Seems like I have to fight my current paranoia fit ('cause GitHub is beyond suspicion even though I can’t get it having a file absent from the repository) and do the work from scratch. Anyway, excuse my taking your time.

Yours` sehrguey

I would guess the .sqlite3 file was not checked in your Git version control system to begin with (that’s usually how it’s configured in the .gitignore file). So when you deployed the 2.3.3 app initially it created that sqlite3 database file on the hosting server, but this does not mean that file was present in your own copy of the repository. So when pushing your local repo to GitHub, that file was not present, hence why it was not present in GitHub.

1 Like

Your guess is right, I never checked as deep as .gitignore file but here enters divergence: I copied to GitHub (years ago) not from deployed app but from that working on my PC. The further the merrier - a week ago I downloaded the app from the github repository including /db/development.sqlite3 to start this discussion. Two days ago I once again visited folder db at the said github repository to find that /db/development.sqlite3 is simply absent there. The situation is obviously beyond this forum is for. Something to shrug at and go live your life on. Yours` sehrguey

If that file was at some point committed to the repository, you can always check that in the git commit history. But I don’t see how that would be the case if it’s excluded from version control as instructed in the .gitignore file.

The reason this database file is excluded from version control is, precisely because it’s a database and its contents need to change, whereas version control is used to store files that don’t change “on their own”.

and you’re right again .gitignore content lists /db/*.sqlite3 file which explains why it was blank in the repository when I recently downloaded it back, yet the file’s disappearance after that still remains a mystery. Unfortunately, I can’t use git control version because the PC used when making the app was last long ago. So I can’t see any chance of the db restoration from the app kept at GitHub, but I do appreciate your kind attention and your elucidation of a couple of points to me.

Yours`

sehrguey

1 Like