Deploying an app using the sqlite3 database through django WinXP/7 - windows

Current System: Windows XP / Windows 7 (problem occuring for both)
After following the guidelines for deployment from the following:
https://devcenter.heroku.com/articles/python
and by testing by using a simple poll application I am successfully able to push the application through heorku except that after checking the logs the following error appears:
2012-04-27T08:14:42+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigure
d: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No m
odule named _sqlite3
This also occurs when attempting to sync the database.
Here is the current configuration of the database in the settings.py file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'database.sqlite', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
I am aware is it a sqlite3 database, and I have been told that it should still allow heroku to deploy the app without any errors.
I have followed through using the following potential solutions that are related to this problem:
No module named _sqlite3
How do I set up SQLite with a Django project?
http://groups.google.com/group/django-users/browse_thread/thread/185f981f432346f1
Any help will be appreciated! Please let me know if additional Information is needed.

Heroku does not support sqlite, since it only provides a read-only filesystem.

I had the same error with the settings file. Looking through the Heroku logs, it turned out that my settings.py file was failing for various reasons. Once I fixed those issues, Django stopped complaining about missing database settings.
One of the things that caused this issue was a monkey patch I was using to allow sub-selects as tables in QuerySet extra(). This patch is at the end of my settings file.
# Override default behaviour of compiler to quote table names when table name is a sub-query
from django.db.models.sql.compiler import SQLCompiler
_quote_name_unless_alias = SQLCompiler.quote_name_unless_alias
SQLCompiler.quote_name_unless_alias = lambda self,name: name if name.startswith('(') else _quote_name_unless_alias(self,name)
This patch apparently requires that DATABASES already be correctly specified at that point. Since Heroku appends the magic DATABASES configuration to the end of the settings file (i.e. after the monkey patch), I had to manually insert their configuration above my monkey patch.

Related

Laravel 5.7 mongodb atlas connection problem using jenssegers/mongodb

I want to connect my laravel 5.7 application(I used the 3.4 version of jenssegers/mongodb) with a mongodb in atlas, I tried in localhost(I isntalled the mongo extension) and everything is ok but with atlas i got an error message:
Failed to parse MongoDB URI:
'mongodb://root%3Acluster0.xxx.mongodb.net%3A27017%2Fhddatabase%3FretryWrites%3Dtrue%26w%3Dmajority'.
Invalid host string in URI.
My env file:
DB_CONNECTION=mongodb
DB_DSN="mongodb://root:password#cluster0.xxx.mongodb.net:27017/hddatabase?retryWrites=true&w=majority"
DB_DATABASE=hddatabase
My database config:
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('DB_DSN'),
'database' => env('DB_DATABASE'),
],
TL;DR: The url is wrong. "+srv" part is missing.
Please copy the url from the Atlas Connection Wizard:
You can open the connection from the Cluster View:
Details
Atlas provides a replica set cluster of 3 mongo db instances by default. Your local database is standalone.
There are 2 formats to connect to mongodb:
mongodb:// is the legacy one that requires all members of the replica set to be explicitly present in the url. E.g.: mongodb://<username>:<password>#cluster0-shard-00-00.xxx.mongodb.net:27017,cluster0-shard-00-01.xxx.mongodb.net:27017,cluster0-shard-00-02.xxx.mongodb.net:27017/<dbname>?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority
mongodb+srv:// is the "srv" format which lets the driver to retrieve replica set configuration from mongodb itself, so the url is much simpler: mongodb+srv://<username>:<password>#cluster0.xxx.mongodb.net/<dbname>?retryWrites=true&w=majority
You are using the later format and the legacy schema so the driver complains.
As a side note it is advisable to use configuration options username and password as documented in https://github.com/jenssegers/laravel-mongodb#configuration rather than pass them in the url. URL format requires special characters like #, /, etc in the password to be escaped, which unnecessarily complicates credentials management.
Try with this DNS maybe :
mongodb://root:password#cluster0.xxx.mongodb.net:27017
Even with the 'srv' format I'm getting the same error, The problem is that I'm using the version 3.4.0 of jenssegers/mongodb, I upgraded to version 3.4.6 and used the 'srv' format and problem is solved now !

WEBrick run on hanami 1.0.0 shows errors because of wrong inflection

I generated model with hanami generate model stimulus. Then I fixed "stimuluses" to "stimuli" in the migration file name and inside, the table name.
Everytime I load a page I get this error in the server console window:
[ROM::Relation[Stimuluses]] failed to infer schema. Make sure tables exist before ROM container is set up. This may also happen when your migration tasks load ROM container, which is not needed for migrations as only the connection is required (schema parsing returned no columns, table "stimuluses" probably doesn't exist)
I looked into the libraries and found that this functionality has Inflecto library. Then I tried both adding to hanami project this:
# /config/initializers/inflecto.rb
require 'inflecto'
Inflecto.inflections do |inflect|
inflect.irregular('stimulus', 'stimuli')
end
And editing the defualt library file:
# gems/inflecto-0.0.2/lib/inflecto/defaults.rb
Inflecto.inflections do |inflect|
...
inflect.irregular('stimulus', 'stimuli')
...
end
But the message is still there after restarting the server.
Is this something I should solve and if yes, how to do this?
EDIT:
Also tried:
# /config/initializers/inflector.rb
require 'hanami/utils/inflector'
Hanami::Utils::Inflector.inflections do
exception 'stimulus', 'stimuli'
end
I'm assuming we are talking about Hanami v1.0.0, right?
You nearly succeeded. What hit you is that initializers seem to be not loaded when executing hanami commands and maybe a bug in code reloading. So instead of an initializer put it into a file that gets loaded when hanami commands are executed or require the initializer file in such a place. E.g.,
# config/initializers/inflections.rb
require 'hanami/utils/inflector'
Hanami::Utils::Inflector.inflections do
exception 'stimulus', 'stimuli'
end
and then in your environment file
# config/environment.rb
# ...
require_relative 'initializers/inflections.rb'
# ...
I'm not sure if that is a good place to put custom inflection rules, but at least it works.

Ruby Sinatra/Postgres - can't connect to heroku database with PG.connect?

I am trying to get a site set up on Heroku using Sinatra and PostgreSQL. It worked locally (connecting to local database), but after pushing it to Heroku and changing my PG.connect to reflect that, I get an Internal Server Error the moment a page tries to access the database.
require 'uri'
require 'pg'
uri = URI.parse(ENV['DATABASE_URL'])
def db(uri)
begin
connection = PG.connect(uri.hostname, uri.port, nil, nil, uri.path[1..-1], uri.user, uri.password)
yield(connection)
ensure
connection.close
end
end
I am pretty sure these are parsing correctly, because ENV['DATABASE_URL'] displays the full postgres://user:password#host:port/database information that I'm expecting, and if I do the same in IRB uri.hostname, ui.port, etc all return what's expected .
This is my first time trying to get a site working on Heroku, so I am not even sure how to troubleshoot this. (And I googled for about all of yesterday.)
Results for heroku pg:
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 9.4.2
Created: 2015-05-30 19:24 UTC
Data Size: 17.7 MB
Tables: 5
Rows: 9320/10000 (In compliance, close to row limit)
Fork/Follow: Unsupported
Rollback: Unsupported
And all the tables show up when when I do heroku pg:psql <database> from the cli.
Some answers I've seen said to add database.yml to my root app directory, so:
production:
adapter: 'postgresql'
database: '<database>'
host: ENV['DATABASE_URL']
username: '<username>'
There's probably something simple I'm missing, but I haven't seen a complete guide for Sinatra/PSQL on Heroku - nothing that goes specifically into setting up and connecting to your database. (Everything seems Rails-related.)
In your database.yml file you need to specify the correct host for the host entry. You are passing what is stored in DATABASE_URL (something like postgres://user:password#host:port/database) but it should just be the host.
You will also need to specify a port if it isn't the default for PostgreSQL.
Edit: should also point out if you plan to store the host (or anything else - you definitely should for username and password) in an environment variable you'll need to wrap it, e.g. <%= ENV['HOST'] %>, not just ENV['HOST'] (i.e. how you have in the database.yml excerpt above)

Telling Puppet to only run an install if registry key is not present

I have written manifest that installs an .exe and applies a hotfix to it every-time it installs on a new machine.
windowsinstaller { 'AppFabric install 1.1 install':
software_title => 'AppFabric 1.1 for Windows Server',
software_path => '/Microsoft/AppFabric1.1/WindowsServerAppFabricSetup_x64.exe',
install_options => ['/i','/SkipUpdates'],
}
windowsinstaller { 'AppFabric 1.1 HotFix install':
software_title => 'Windows Server AppFabric v1.1 CU5 [KB2932678]',
software_path => '/Microsoft/AppFabric1.1/AppFabric1.1-KB2932678-x64-ENU.exe',
install_options => ['/q','/norestart'],
subscribe => Windowsinstaller['AppFabric install 1.1 install']
}
service { 'Remote Registry Service':
name => 'RemoteRegistry',
ensure => running,
restart => true,
}
I am trying to get this install to run only if it's registry key is absent.
Using puppetlabs registry module you can manage keys, redirect them, and change the values.
reference: http://puppetlabs.com/blog/module-of-the-week-puppetlabs-registry-windows
Unfortunately, I can't seem to find a way to simply check if the key is there, I can either delete it or make sure its present using ensure => present and ensure => absent.
As I can't put resources into variables I am finding it hard to use conditional statements, and as present and absent set the key instead of check it, I don't think I can use meta parameters with the registry_key resource.
I know that I can wrap everything in an if statement and use a custom fact but I have been told that this is not the right way to proceed.
If anyone has an example of where this has been done before either using this module or something else registered in the puppet forge or any ideas it would be greatly appreciated.
The user manbart found the answer 7 months ago with this question
Exec onlyif registry value is not present
calling reg.exe to query the registry in an exec resource.

Puppet Server and Client working Good but still manifest file doesn't get executed

I am currently working on puppet using Amazon Fedora EC2 instances. Both Puppet Server and Client are working fine. I am able to create certificate from client and server is able to sign that but still whatever code I have written in manifest files doesn’t get executed.
Below mentioned is my code in Site.pp file :
class test_class {
file { “/tmp/testfile”:
ensure => present,
mode => 644,
owner => root,
group => root
}
}
node puppetclient {
include test_class
}
Here, puppetclient is the hostname of client. But still after signing certificate /tmp/testfile doesn’t get created.
DNS is also working perfectly fine. I can ping puppetserver(named as puppet) from puppet client.
Can you please tell me what must be the possible mistake ??
It's probably just a typo in the question, but the default catalog file is 'site.pp', not 'Site.pp', so try it with 'site.pp' instead.

Resources