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

Setup project from already installed repository doesn't work #374

Closed
jhhazelaar opened this issue Nov 5, 2024 · 3 comments · Fixed by #375
Closed

Setup project from already installed repository doesn't work #374

jhhazelaar opened this issue Nov 5, 2024 · 3 comments · Fixed by #375
Labels
bug Something isn't working

Comments

@jhhazelaar
Copy link
Contributor

Bug description

After installing a new project with the eloquent driver and setup repository. When installing de new project trough the repository the composer install gives a error on the package discover composer script.

When installing with --no-scripts there is no error but then you can't run the migrate command. You get the same error.

The error is:

SQLSTATE[HY000]: General error: 1 no such table: sites (Connection: sqlite, SQL: select * from "sites")

How to reproduce

Create new project with statamic new.
Select storing content and data in de database.
Select initialize repository
Select your database of choice
Select to store everything in the database
Commit everything

The project is now setup.

Run git clean command to mimic a new clone: git clean -fdX

Then run composer install. Or after composer install --no-scripts run php artisan migrate

Logs

[previous exception] [object] (PDOException(code: HY000): SQLSTATE[HY000]: General error: 1 no such table: sites at /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Connection.php:407)
[stacktrace]
#0 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Connection.php(407): PDO->prepare('select * from \"...')
#1 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Connection.php(812): Illuminate\\Database\\Connection->Illuminate\\Database\\{closure}('select * from \"...', Array)
#2 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Connection.php(779): Illuminate\\Database\\Connection->runQueryCallback('select * from \"...', Array, Object(Closure))
#3 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Connection.php(398): Illuminate\\Database\\Connection->run('select * from \"...', Array, Object(Closure))
#4 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3132): Illuminate\\Database\\Connection->select('select * from \"...', Array, true)
#5 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3117): Illuminate\\Database\\Query\\Builder->runSelect()
#6 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3705): Illuminate\\Database\\Query\\Builder->Illuminate\\Database\\Query\\{closure}()
#7 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3116): Illuminate\\Database\\Query\\Builder->onceWithColumns(Array, Object(Closure))
#8 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(759): Illuminate\\Database\\Query\\Builder->get(Array)
#9 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(741): Illuminate\\Database\\Eloquent\\Builder->getModels(Array)
#10 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(693): Illuminate\\Database\\Eloquent\\Builder->get(Array)
#11 /Users/janhenk/Sites/statamic-eloquent/vendor/statamic/eloquent-driver/src/Sites/Sites.php(11): Illuminate\\Database\\Eloquent\\Model::all()
#12 /Users/janhenk/Sites/statamic-eloquent/vendor/statamic/cms/src/Sites/Sites.php(105): Statamic\\Eloquent\\Sites\\Sites->getSavedSites()
#13 /Users/janhenk/Sites/statamic-eloquent/vendor/statamic/cms/src/Sites/Sites.php(24): Statamic\\Sites\\Sites->setSites()
#14 [internal function]: Statamic\\Sites\\Sites->__construct()
#15 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(983): ReflectionClass->newInstanceArgs(Array)
#16 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(815): Illuminate\\Container\\Container->build('Statamic\\\\Eloque...')
#17 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1046): Illuminate\\Container\\Container->resolve('Statamic\\\\Eloque...', Array, false)
#18 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(324): Illuminate\\Foundation\\Application->resolve('Statamic\\\\Eloque...', Array, false)
#19 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(931): Illuminate\\Container\\Container->Illuminate\\Container\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
#20 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(815): Illuminate\\Container\\Container->build(Object(Closure))
#21 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1046): Illuminate\\Container\\Container->resolve('Statamic\\\\Sites\\\\...', Array, true)
#22 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(751): Illuminate\\Foundation\\Application->resolve('Statamic\\\\Sites\\\\...', Array)
#23 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1028): Illuminate\\Container\\Container->make('Statamic\\\\Sites\\\\...', Array)
#24 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(1559): Illuminate\\Foundation\\Application->make('Statamic\\\\Sites\\\\...')
#25 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(237): Illuminate\\Container\\Container->offsetGet('Statamic\\\\Sites\\\\...')
#26 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(208): Illuminate\\Support\\Facades\\Facade::resolveFacadeInstance('Statamic\\\\Sites\\\\...')
#27 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(352): Illuminate\\Support\\Facades\\Facade::getFacadeRoot()
#28 /Users/janhenk/Sites/statamic-eloquent/vendor/statamic/cms/src/Stache/ServiceProvider.php(45): Illuminate\\Support\\Facades\\Facade::__callStatic('all', Array)
#29 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Statamic\\Stache\\ServiceProvider->boot()
#30 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#31 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#32 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#33 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Container/Container.php(690): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#34 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1119): Illuminate\\Container\\Container->call(Array)
#35 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1100): Illuminate\\Foundation\\Application->bootProvider(Object(Statamic\\Stache\\ServiceProvider))
#36 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(Statamic\\Stache\\ServiceProvider), 'Statamic\\\\Stache...')
#37 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1099): array_walk(Array, Object(Closure))
#38 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#39 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(316): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#40 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(473): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#41 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(195): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#42 /Users/janhenk/Sites/statamic-eloquent/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1203): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#43 /Users/janhenk/Sites/statamic-eloquent/artisan(13): Illuminate\\Foundation\\Application->handleCommand(Object(Symfony\\Component\\Console\\Input\\ArgvInput))
#44 {main}
"}

Environment

Can't run `php please support:details`, but after changing sites driver to file in `config/statamic/eloquent-driver.php`:

Environment
Application Name: Statamic
Laravel Version: 11.30.0
PHP Version: 8.3.11
Composer Version: 2.7.9
Environment: production
Debug Mode: OFF
URL: localhost
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: null
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 1
Sites: 1
Stache Watcher: Disabled (auto)
Static Caching: Disabled
Version: 5.36.0 Solo

Statamic Addons
statamic/eloquent-driver: 4.16.1

Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: eloquent
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: eloquent
Navigation Trees: eloquent
Navigations: eloquent
Revisions: file
Sites: file
Taxonomies: eloquent
Terms: eloquent
Tokens: eloquent

Additional details

After changing the sites driver to file you can run the migration and it works. After this everything works normal

@jhhazelaar jhhazelaar added the bug Something isn't working label Nov 5, 2024
@ryanmitchell
Copy link
Contributor

@duncanmcclean this seems more related to the installer. Maybe it needs to run migrations before setting configs?

@jhhazelaar
Copy link
Contributor Author

@ryanmitchell @duncanmcclean is there any oppose of checking if the table exists in the Statamic\Eloquent\Sites function getSavedSites?

Just above

$sites = app('statamic.eloquent.sites.model')::all();
we can check if the schema exists and return the fallback conig:

        $sitesTable = config('statamic.eloquent-driver.table_prefix', '').'entries';
        if(! Schema::hasTable($sitesTable)) {
            return $this->getFallbackConfig();
        };

@jhhazelaar
Copy link
Contributor Author

I've create a pull request for the above suggestion: #375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants