Skip to content

Installation: manual creation of tables? #205

Closed

Description

@stefangweichinger

Sorry, I don't understand this exactly.

I have a nc-32-stack with postgresql as db-backend for nextcloud.

When I install the addon ( I cloned https://github.com/rotdrop/user_sql as mentioned in #203 (comment) .. using the 32-branch ) it breaks the nextcloud-GUI from the start:

"args":[]}],"File":"/var/www/html/lib/private/DB/ConnectionFactory.php","Line":107},"message":"OC\\DB\\ConnectionFactory::getConnection(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/apps/user_sql/lib/Query/DataQuery.php on line 166 in file '/var/www/html/lib/private/DB/ConnectionFactory.php' line 107","exception":{},"CustomMessage":"OC\\DB\\ConnectionFactory::getConnection(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/apps/user_sql/lib/Query/DataQuery.php on line 166 in file '/var/www/html/lib/private/DB/ConnectionFactory.php' line 107"}}

I can't even use the GUI to configure the addon.

So "getting started" https://github.com/nextcloud/user_sql?tab=readme-ov-file#getting-started already fails for me.

And I don't understand https://github.com/nextcloud/user_sql?tab=readme-ov-file#integrations

I already have an existing mariadb which I want to connect to for authenticating users (it's a postfixadmin-database, btw). Do I have to create these tables in the nextcloud-db-backend? I assume, no.

But why does simply enabling the non-configured addon break the nc-gui already?

pls advise, thanks all!

Activity

  1. rotdrop commented on Dec 4, 2025

    @rotdrop
    Contributor

    Hi, there is now the possibility to add issues also on my fork (probably switched off by default on forks). However, the error your mention above means that the type of the database is not configured. The configuration is in the admin settings in the "SQL Backends" section.

    For the "getting-started" stuff in the README: I fear it is a little bit unclear in its formulation. So basically: use the existing database and configure in "SQL Backends" section the database connection to your existing database (user password, server etc.) and then configure the mapping between the existing database and the user/group information needed for NC, e.g. for the "User Table" set the "UID" input to the field containing the user-id in your existing database and so on .

  2. stefangweichinger commented on Dec 4, 2025

    @stefangweichinger
    Author

    Hi, there is now the possibility to add issues also on my fork (probably switched off by default on forks). However, the error your mention above means that the type of the database is not configured. The configuration is in the admin settings in the "SQL Backends" section.

    Thanks for the quick reply!

    As mentioned I don't even get into that section ;-)

    For the "getting-started" stuff in the README: I fear it is a little bit unclear in its formulation.

    I agree!

    So basically: use the existing database and configure in "SQL Backends" section the database connection to your existing database (user password, server etc.) and then configure the mapping between the existing database and the user/group information needed for NC, e.g. for the "User Table" set the "UID" input to the field containing the user-id in your existing database and so on .

    "existing database": the nc-backend-database or the database with the authentication-credentials?

    Do I have to create any tables for the nc_sql-addon myself? "getting started" does not mention creating tables.

    As mentioned I have existing users/hashes etc in the mariadb-backend of my mail server.

    As far as I understand it should be enough to point the addon to these existing tables, getting the fields right (and hoping that it only reads data and doesn't edit anything ;-) ).

  3. stefangweichinger commented on Dec 4, 2025

    @stefangweichinger
    Author

    Hi, there is now the possibility to add issues also on my fork (probably switched off by default on forks).

    Should we switch there?

  4. rotdrop commented on Dec 4, 2025

    @rotdrop
    Contributor

    I think we can stay here; I think your questions are relevant for both repositories, and after all I still have the plan to re-unite both and act as a maintainer for this repository.

  5. rotdrop commented on Dec 4, 2025

    @rotdrop
    Contributor

    Hi, there is now the possibility to add issues also on my fork (probably switched off by default on forks). However, the error your mention above means that the type of the database is not configured. The configuration is in the admin settings in the "SQL Backends" section.

    Thanks for the quick reply!

    As mentioned I don't even get into that section ;-)

    Oops. Sorry, just did not get the "'t" from the "can't". I have to look into that. The mistake is that the app tries to connect to the database without configuration. That should be easily fixable. As a workaround one could try to set configuration values with the "occ" command, but only if one knows the correct configuration keys (that woudl require reading through the sourcecode).

    For the "getting-started" stuff in the README: I fear it is a little bit unclear in its formulation.

    I agree!

    So basically: use the existing database and configure in "SQL Backends" section the database connection to your existing database (user password, server etc.) and then configure the mapping between the existing database and the user/group information needed for NC, e.g. for the "User Table" set the "UID" input to the field containing the user-id in your existing database and so on .

    "existing database": the nc-backend-database or the database with the authentication-credentials?

    The existing non-nextcloud database with the "external" authentication data.

    Do I have to create any tables for the nc_sql-addon myself? "getting started" does not mention creating tables.

    No. That is were the README is really badly written. The tables mentioned there are rather an example how an external database could look like.

    As mentioned I have existing users/hashes etc in the mariadb-backend of my mail server.

    As far as I understand it should be enough to point the addon to these existing tables, getting the fields right (and hoping that it only reads data and doesn't edit anything ;-) ).

    Definitely.

  6. rotdrop commented on Dec 4, 2025

    @rotdrop
    Contributor

    For the error message in the your first comment, did come with a stack-trace? That would be helpful.

  7. stefangweichinger commented on Dec 4, 2025

    @stefangweichinger
    Author

    For the error message in the your first comment, did come with a stack-trace? That would be helpful.

    I took the lines out of nextcloud.log and only used a part of it as it is quite a long block of lines.

    pls let me know how and where to look for that stack trace. The gui error doesn't tell me much, I see an internal error with some random "Anfragekennung: vcu39P9vWghCv8mxgd9j" (random to me).

  8. stefangweichinger commented on Dec 4, 2025

    @stefangweichinger
    Author

    Do I have to create any tables for the nc_sql-addon myself? "getting started" does not mention creating tables.

    No. That is were the README is really badly written. The tables mentioned there are rather an example how an external database could look like.

    This is what I assumed and what is now answered, thanks!

  9. stefangweichinger commented on Dec 4, 2025

    @stefangweichinger
    Author

    I think I have found the needed table and fields in the postfixadmin-database. So I am ready to test if we can find out why my setup crashes so far.

    I restarted the containers, unfortunately I don't see "Stack trace" in nextcloud.log or the logs from docker-compose.

    I share the full entry from nextcloud.log:

    {"reqId":"znWx97J9iaBxAu0en52s","level":3,"time":"2025-12-04T14:33:55+01:00","remoteAddr":"62.40.171.237","user":"stefan.weichinger","app":"index","method":"GET","url":"/index.php/settings/admin/overview","message":"OC\\DB\\ConnectionFactory::getConnection(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/apps/user_sql/lib/Query/DataQuery.php on line 166 in file '/var/www/html/lib/private/DB/ConnectionFactory.php' line 107","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36","version":"32.0.2.2","exception":{"Exception":"Exception","Message":"OC\\DB\\ConnectionFactory::getConnection(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/apps/user_sql/lib/Query/DataQuery.php on line 166 in file '/var/www/html/lib/private/DB/ConnectionFactory.php' line 107","Code":0,"Trace":[{"file":"/var/www/html/lib/private/AppFramework/App.php","line":153,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Settings\\Controller\\AdminSettingsController"},"index"]},{"file":"/var/www/html/lib/private/Route/Router.php","line":321,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Settings\\Controller\\AdminSettingsController","index",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"settings.adminsettings.index","section":"overview"}]},{"file":"/var/www/html/lib/base.php","line":1061,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/settings/admin/overview"]},{"file":"/var/www/html/index.php","line":25,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/html/lib/private/AppFramework/Http/Dispatcher.php","Line":150,"Previous":{"Exception":"TypeError","Message":"OC\\DB\\ConnectionFactory::getConnection(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/apps/user_sql/lib/Query/DataQuery.php on line 166","Code":0,"Trace":[{"file":"/var/www/html/apps/user_sql/lib/Query/DataQuery.php","line":166,"function":"getConnection","class":"OC\\DB\\ConnectionFactory","type":"->","args":[null,{"host":null,"password":null,"user":null,"dbname":null,"tablePrefix":"","0":"And 1 more entries, set log level to debug to see all entries"}]},{"file":"/var/www/html/apps/user_sql/lib/Query/DataQuery.php","line":108,"function":"connectToDatabase","class":"OCA\\UserSQL\\Query\\DataQuery","type":"->","args":[]},{"file":"/var/www/html/apps/user_sql/lib/Query/DataQuery.php","line":300,"function":"execQuery","class":"OCA\\UserSQL\\Query\\DataQuery","type":"->","args":["find_user_groups",{"uid":"stefan.weichinger"},-1,0]},{"file":"/var/www/html/apps/user_sql/lib/Repository/GroupRepository.php","line":74,"function":"queryEntities","class":"OCA\\UserSQL\\Query\\DataQuery","type":"->","args":["find_user_groups","OCA\\UserSQL\\Model\\Group",{"uid":"stefan.weichinger"}]},{"file":"/var/www/html/apps/user_sql/lib/Backend/GroupBackend.php","line":277,"function":"findAllByUid","class":"OCA\\UserSQL\\Repository\\GroupRepository","type":"->","args":["stefan.weichinger"]},{"file":"/var/www/html/lib/private/Group/Manager.php","line":378,"function":"getUserGroups","class":"OCA\\UserSQL\\Backend\\GroupBackend","type":"->","args":["stefan.weichinger"]},{"file":"/var/www/html/lib/private/Group/Manager.php","line":357,"function":"getUserIdGroupIds","class":"OC\\Group\\Manager","type":"->","args":["stefan.weichinger"]},{"file":"/var/www/html/lib/private/Group/Manager.php","line":334,"function":"isInGroup","class":"OC\\Group\\Manager","type":"->","args":["stefan.weichinger","admin"]},{"file":"/var/www/html/lib/private/Settings/DeclarativeManager.php","line":134,"function":"isAdmin","class":"OC\\Group\\Manager","type":"->","args":["stefan.weichinger"]},{"file":"/var/www/html/apps/settings/lib/Controller/CommonSettingsTrait.php","line":146,"function":"getFormsWithValues","class":"OC\\Settings\\DeclarativeManager","type":"->","args":[{"__class__":"OC\\User\\User"},"admin","overview"]},{"file":"/var/www/html/apps/settings/lib/Controller/AdminSettingsController.php","line":56,"function":"getIndexResponse","class":"OCA\\Settings\\Controller\\AdminSettingsController","type":"->","args":["admin","overview"]},{"file":"/var/www/html/lib/private/AppFramework/Http/Dispatcher.php","line":204,"function":"index","class":"OCA\\Settings\\Controller\\AdminSettingsController","type":"->","args":["overview"]},{"file":"/var/www/html/lib/private/AppFramework/Http/Dispatcher.php","line":118,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Settings\\Controller\\AdminSettingsController"},"index"]},{"file":"/var/www/html/lib/private/AppFramework/App.php","line":153,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Settings\\Controller\\AdminSettingsController"},"index"]},{"file":"/var/www/html/lib/private/Route/Router.php","line":321,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Settings\\Controller\\AdminSettingsController","index",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"settings.adminsettings.index","section":"overview"}]},{"file":"/var/www/html/lib/base.php","line":1061,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/settings/admin/overview"]},{"file":"/var/www/html/index.php","line":25,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/html/lib/private/DB/ConnectionFactory.php","Line":107},"message":"OC\\DB\\ConnectionFactory::getConnection(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/apps/user_sql/lib/Query/DataQuery.php on line 166 in file '/var/www/html/lib/private/DB/ConnectionFactory.php' line 107","exception":{},"CustomMessage":"OC\\DB\\ConnectionFactory::getConnection(): Argument #1 ($type) must be of type string, null given, called in /var/www/html/apps/user_sql/lib/Query/DataQuery.php on line 166 in file '/var/www/html/lib/private/DB/ConnectionFactory.php' line 107"}}
    
  10. stefangweichinger commented on Dec 5, 2025

    @stefangweichinger
    Author

    Can I add some initial empty/dummy config somewhere to get this working?

  11. rotdrop commented on Dec 5, 2025

    @rotdrop
    Contributor

    Hi, I found the reason. That connectToDatabase() now throws an exception when called with empty configuration; this produces then a stack trace. Bubbling up the path one finds that user_sql is queried although it is not yet configured. Actually, there is a method isConfigured(), but that is not (probably no longer since ages) called from the NC core library:

    public function isConfigured()

    I think the correct fix is to disable the backend registration in app setup code in lib/AppInfo/Application.php. The following commit should fix it, please give it a try:

    rotdrop/user_sql@601f772

  12. rotdrop commented on Dec 5, 2025

    @rotdrop
    Contributor

    Oops. Seemingly it was me damaging this app then when converting the app from legacy setup code to the newer 'IBootstrap' scheme. I just never stumbled over it because I always had a working configuration. Of course, this calls for the setup of a test-suite ...

  13. stefangweichinger commented on Dec 5, 2025

    @stefangweichinger
    Author

    Oops. Seemingly it was me damaging this app then when converting the app from legacy setup code to the newer 'IBootstrap' scheme. I just never stumbled over it because I always had a working configuration. Of course, this calls for the setup of a test-suite ...

    ;-) ... thanks for checking things. As far as I understand I can skip testing that patch, then? looking forward to any improvements, ready to test

  14. rotdrop commented on Dec 5, 2025

    @rotdrop
    Contributor

    Oops. Seemingly it was me damaging this app then when converting the app from legacy setup code to the newer 'IBootstrap' scheme. I just never stumbled over it because I always had a working configuration. Of course, this calls for the setup of a test-suite ...

    ;-) ... thanks for checking things. As far as I understand I can skip testing that patch, then? looking forward to any improvements, ready to test

    No, the patch is just ok, my previous comment was just reasoning about the cause of the bug. So please test the current state of my fork at

    https://github.com/rotdrop/user_sql/tree/production/cafevdb/stable32

    It should fix the "called without config" issue.

  15. stefangweichinger commented on Dec 5, 2025

    @stefangweichinger
    Author

    yes, it does, thank you. I can now start my configuration tests.
    A very basic question : does the addon strictly read from the SQL backends or does it also write things?

    I think I see it already.
    And I configured the GRANTS in mysql for the used db-user for readonly for tests now

  16. rotdrop commented on Dec 5, 2025

    @rotdrop
    Contributor

    The app writes if it can, and there are scenarios were this might be even desirable (users changing their passwords for example).

  17. stefangweichinger commented on Dec 8, 2025

    @stefangweichinger
    Author

    thanks @rotdrop // nearly forgot to mention that I have the basic function up and running now in my test stack.
    Logging in works with test user(s) and so far the mapping is OK: the internal NC users and their data are assigned and found, so until now it looks as if I can substitute the former user_external-setup with the user_sql-setup (I will see if I can enhance my config by adding/using more db-fields etc).

    I wonder if this leads to more or less load on the database: so far the user_external-addon kept several imapd-processes open and dovecot somehow "buffered" the db-access for authentication. Does user_sql somehow take care of this, are there effects to consider when switching from test-stack to production where I might have ~80 sessions in parallel? In the end there should be less load or at least less processes as that intermediate layer isn't needed anymore.

    sorry for drifting, this isn't exactly on topic anymore ;-)

  18. rotdrop commented on Dec 8, 2025

    @rotdrop
    Contributor

    thanks @rotdrop // nearly forgot to mention that I have the basic function up and running now in my test stack. Logging in works with test user(s) and so far the mapping is OK: the internal NC users and their data are assigned and found, so until now it looks as if I can substitute the former user_external-setup with the user_sql-setup (I will see if I can enhance my config by adding/using more db-fields etc).

    Good to know. So basically things are working :)

    I wonder if this leads to more or less load on the database: so far the user_external-addon kept several imapd-processes open and dovecot somehow "buffered" the db-access for authentication. Does user_sql somehow take care of this, are there effects to consider when switching from test-stack to production where I might have ~80 sessions in parallel? In the end there should be less load or at least less processes as that intermediate layer isn't needed anymore.

    sorry for drifting, this isn't exactly on topic anymore ;-)

    user_sql keeps an internal cache using whatever NC provides as "distributed memory cache", see

    https://github.com/nextcloud/user_sql/blob/5cdb45bd08e9a3fc40ac93243a7803e8264a6da5/lib/Cache.php

    It never bothered me (apart from invalidating the cache) but this transfers the load from the database server to the memcache providers (depends on configuration e.g. APCu, e.g. Redis, e.g. MemCached).

    Performance then depends upon how direct database access timings compare to cache access timing ...

  19. stefangweichinger commented on Dec 9, 2025

    @stefangweichinger
    Author

    @rotdrop thanks. Maybe it's not an issue at all, I just wondered. I expect to see less open dovecot/imap-login processes with user_sql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions