jacobwb / hashover-next

This branch will be HashOver 2.0
GNU Affero General Public License v3.0
420 stars 87 forks source link

Is there an initialize Database script for switching to SQL, or am I just missing something? #310

Open sysRoot opened 2 years ago

sysRoot commented 2 years ago

I recently installed HashOver, in a subdirectory and handled it with Caddy. All was working well until I enabled SQL. I think I missed a step possibly. Documentation is sparse.

HashOver: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mpcomdb.comments' doesn't exist 

It works wonderfully, except XML isn't really for me, I'd rather have everything centralized in Databases, in case for some reason I have to move servers or something, then all I have to move are my frontend/backend.

If I missed some sort of procedure, I am not aware... but the user is set appropriately, as is database and pw in secrets

        // OPTIONAL SQL INFORMATION

        // Type of database, sqlite or mysql
        protected $databaseType = 'mysql';

        // Database name
        protected $databaseName = 'mpcomdb';

        // SQL database host name
        protected $databaseHost = 'localhost';

        // SQL database port number
        protected $databasePort = '3306';

        // SQL database login user
        protected $databaseUser = 'topin';

        // SQL database login password
        protected $databasePassword = '[OMITTED]';

        // SQL database character set
        protected $databaseCharset = 'utf8';

All seems to check out fine, user has ALL Privileges on database.

jacobwb commented 2 years ago

HashOver will automatically create the table it needs to store the comments, but it will not create the database. This is why the database name is configurable in the secrets.php file. Perhaps the database should be automatically created, but I felt that was too intrusive, so it doesn't get automatically created right now.

All you should need to do is create the mpcomdb database you set in the secrets.php file.

sysRoot commented 2 years ago

Fair enough. I didn't mean create... perhaps SEED was a better word. It might have had to do with the fact that I dropped the database as a testing procedure.

So I re-cloned hashover, moved it to the same directory after removing everything, and reset it up. Sorry, should've tried that first. It works great in my nextJS app btw. Clean and concise... way better than running some other alternatives I tried :)

sysRoot commented 2 years ago

Well I thought it was fixed, after creating everything from scratch but no. mpcomdb.comments not found still persists, when I thought it was working, it had saved to XML format agan

sysRoot commented 2 years ago

Well I thought it was fixed, after creating everything from scratch but no. mpcomdb.comments not found still persists, when I thought it was working, it had saved to XML format agan

To emphasize setup, I have a properly chowned directory at /var/www/html/hoc, owned by caddy:caddy and executed via the caddy fast_cgi directive under a handler directive. I created the table first, assigned privileges, git cloned, moved the hoc directory from my home folder under /home/thero/hoc to /var/html/www/hoc and recursively chowned it again, edited secrets.php, went to the admin of HashOver at meaningpoetry.com/hoc/admin and tried setting it to SQL format. These are the steps I took pretty much to the bone, to setup HashOver. I don't think it has anything to do with Caddy, and the same user writes fine to all my other databases. Yes, I know I should have different SQL users, that is something to address in code/config cleanups later on, but for now it's fine and works, since everything is local. Assigned ALL PRIVILEGES to topin on mpcomdb and double checked. Have dropped the database and recreated it numerous times and have tried git clone from fresh each time, the only thing reused are values from secrets.php

jacobwb commented 2 years ago

I just tried for myself to clone HashOver and create the database from scratch to see if it works, and everything worked.

Are you using actual MySQL or some other derivative? That could cause problems if the syntax is incompatible.

Have you tried creating the database, and comments and page-info tables manually to see if it stops complaining?

I posted the schema here: https://github.com/jacobwb/hashover-next/issues/247#issuecomment-429700010

sysRoot commented 2 years ago

I am using MariaDB to be specific, which I thought was a more or less implementation of the MySQL specification I will try processing the info manually to see. Will report back

sysRoot commented 2 years ago

It immediately started working after plugging in the schema to the mariadb terminal.

jacobwb commented 2 years ago

Great! That probably means that the table creation statement isn't quite compatible with MariaDB, and only a small change will be needed to get it working. I will try to get MariaDB running locally to see what needs changed for HashOver to work with it out of the box. No harm in supporting another type of database.

sysRoot commented 2 years ago

Thank you for your help. The system is awesome and clean, plus the dark theme goes well with the default mode of my site. I would be happy to see the implementation, as it seems MariaDB seems very common across a lot of hosts, from past experience. I only went with it as it is what was recommended by ArchWiki

da2x commented 2 years ago

Great! That probably means that the table creation statement isn't quite compatible with MariaDB.

It is compatible with MariaDB. HashOver creates the tables just fine as long as it has the required permissions. There’s something else wrong.

I had problems in the beginning because I didn’t know that I had to change the data-format setting as well as the databaseType secret. Maybe this was your problem too, @sysRoot? You don’t mention it in your initial post. I’ll address it in the SQL Setup documentation.