From: Tom Hughes Date: Wed, 8 Feb 2012 14:08:49 +0000 (+0000) Subject: Stop pretending we support MySQL X-Git-Tag: live~5875 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/beb0ef6357e426ab08349109d47c3726ed50042e?hp=4ee126a87862437ee440041ea0859255639d0545 Stop pretending we support MySQL --- diff --git a/app/models/acl.rb b/app/models/acl.rb index 94e377343..04f04d8f9 100644 --- a/app/models/acl.rb +++ b/app/models/acl.rb @@ -1,13 +1,3 @@ class Acl < ActiveRecord::Base - scope :address, lambda { |address| where("#{inet_aton} & netmask = address", address) } - -private - - def self.inet_aton - if self.connection.adapter_name == "MySQL" - "inet_aton(?)" - else - "?" - end - end + scope :address, lambda { |address| where("? & netmask = address", address) } end diff --git a/config/postgres.example.database.yml b/config/example.database.yml similarity index 100% rename from config/postgres.example.database.yml rename to config/example.database.yml diff --git a/config/mysql.example.database.yml b/config/mysql.example.database.yml deleted file mode 100644 index cc3f9a1a5..000000000 --- a/config/mysql.example.database.yml +++ /dev/null @@ -1,38 +0,0 @@ -# MySQL (default setup). Versions 4.1 and 5.0 are recommended. -# -# Install the MySQL driver: -# gem install mysql -# On MacOS X: -# gem install mysql -- --include=/usr/local/lib -# On Windows: -# There is no gem for Windows. Install mysql.so from RubyForApache. -# http://rubyforge.org/projects/rubyforapache -# -# And be sure to use new-style password hashing: -# http://dev.mysql.com/doc/refman/5.0/en/old-client.html -development: - adapter: mysql - database: openstreetmap - username: openstreetmap - password: openstreetmap - host: localhost - encoding: utf8 - -# Warning: The database defined as 'test' will be erased and -# re-generated from your development database when you run 'rake'. -# Do not set this db to the same as development or production. -test: - adapter: mysql - database: osm_test - username: osm_test - password: osm_test - host: localhost - encoding: utf8 - -production: - adapter: mysql - database: osm - username: osm - password: osm - host: localhost - encoding: utf8 diff --git a/db/README b/db/README index db4f5c20e..814dcb96c 100644 --- a/db/README +++ b/db/README @@ -1,58 +1,13 @@ Creating database =================== -OSM server uses a database with the following name: +OSM server uses a Postgres database with the following name: openstreetmap You may create it with your preferable client or run next (linux) command: -$ mysql -u -p - -(change with appropriate username of administrative user eg. root ) - -> create database openstreetmap default character set utf8; -> exit - -Creating user, password, and access rights -============================================ - -$ mysql -u -p - -(change with appropriate username of administrative user eg. root ) - -> grant all privileges on openstreetmap.* to 'openstreetmap'@'localhost' identified by 'openstreetmap'; -> flush privileges; -> exit - -Creating functions For MySQL -============================== - -Run this command in the db/functions directory: - -$ make libmyosm.so - -You might also need to install: -- mysql client development libraries: $ sudo apt-get install libmysqlclient16-dev -- ruby development libraries: $ sudo apt-get install ruby1.8-dev -for build to succeed. - -Make sure the db/functions directory is on the MySQL server's library -path and restart the MySQL server. - -On Linux the easiest way to do this is to create /etc/ld.so.conf.d/osm.conf, and place the path to the db/functions directory in it and then run the ldconfig command as root. - -On OS X: sudo ln -s /path_to_your_osm_install/sites/rails_port/db/functions/libmyosm.so /usr/local/lib/libmyosm.so - -Now create the functions as follows: - -$ mysql -u -p openstreetmap - -(change with appropriate username of administrative user eg. root ) - -> create function tile_for_point returns integer soname 'libmyosm.so'; -> create function maptile_for_point returns integer soname 'libmyosm.so'; -> exit +$ createdb openstreetmap Creating functions for PgSQL ============================== @@ -86,4 +41,4 @@ This will create the db for you You will need to make sure the database connection is configured in database.yml in config directory You might start with example configuration provided: -$ cp config/mysql.example.database.yml config/database.yml +$ cp config/example.database.yml config/database.yml diff --git a/db/functions/Makefile b/db/functions/Makefile index 2f97d6d94..231496d40 100644 --- a/db/functions/Makefile +++ b/db/functions/Makefile @@ -7,26 +7,17 @@ else LDFLAGS=-shared endif -all: libmyosm.so libpgosm.so +all: libpgosm.so clean: $(RM) *.so *.o -libmyosm.so: quadtile-mysql.o maptile-mysql.o - cc ${LDFLAGS} -o libmyosm.so quadtile-mysql.o maptile-mysql.o - libpgosm.so: quadtile-pgsql.o maptile-pgsql.o xid_to_int4-pgsql.o cc ${LDFLAGS} -o libpgosm.so quadtile-pgsql.o maptile-pgsql.o xid_to_int4-pgsql.o -quadtile-mysql.o: quadtile.c ${QTDIR}/quad_tile.h - cc `mysql_config --include` -I${QTDIR} -fPIC -O3 -DUSE_MYSQL -c -o quadtile-mysql.o quadtile.c - quadtile-pgsql.o: quadtile.c ${QTDIR}/quad_tile.h cc -I `pg_config --includedir` -I `pg_config --includedir-server` -I${QTDIR} -fPIC -O3 -DUSE_PGSQL -c -o quadtile-pgsql.o quadtile.c -maptile-mysql.o: maptile.c - cc `mysql_config --include` -fPIC -O3 -DUSE_MYSQL -c -o maptile-mysql.o maptile.c - maptile-pgsql.o: maptile.c cc -I `pg_config --includedir` -I `pg_config --includedir-server` -fPIC -O3 -DUSE_PGSQL -c -o maptile-pgsql.o maptile.c diff --git a/db/functions/maptile.c b/db/functions/maptile.c index ed83bcce2..358a3ba75 100644 --- a/db/functions/maptile.c +++ b/db/functions/maptile.c @@ -1,81 +1,22 @@ -#ifndef USE_MYSQL -#ifndef USE_PGSQL -#error One of USE_MYSQL or USE_PGSQL must be defined -#endif -#endif - #include +#include +#include -/* The real maptile-for-point functionality is here */ - -static long long internal_maptile_for_point(double lat, double lon, long long zoom) +Datum +maptile_for_point(PG_FUNCTION_ARGS) { - double scale = pow(2, zoom); - double r_per_d = M_PI / 180; + double lat = PG_GETARG_INT64(0) / 10000000.0; + double lon = PG_GETARG_INT64(1) / 10000000.0; + int zoom = PG_GETARG_INT32(2); + double scale = pow(2, zoom); + double r_per_d = M_PI / 180; unsigned int x; unsigned int y; x = floor((lon + 180.0) * scale / 360.0); y = floor((1 - log(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / M_PI) * scale / 2.0); - return (x << zoom) | y; -} - -#ifdef USE_MYSQL -#ifdef USE_PGSQL -#error ONLY one of USE_MYSQL and USE_PGSQL should be defined -#endif - -#include -#include -#include -#include - -my_bool maptile_for_point_init(UDF_INIT *initid, UDF_ARGS *args, char *message) -{ - if ( args->arg_count != 3 || - args->arg_type[0] != INT_RESULT || - args->arg_type[1] != INT_RESULT || - args->arg_type[2] != INT_RESULT ) - { - strcpy( message, "Your maptile_for_point arguments are bogus!" ); - return 1; - } - - return 0; -} - -void maptile_for_point_deinit(UDF_INIT *initid) -{ - return; -} - -long long maptile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) -{ - double lat = *(long long *)args->args[0] / 10000000.0; - double lon = *(long long *)args->args[1] / 10000000.0; - long long zoom = *(long long *)args->args[2]; - - return internal_maptile_for_point(lat, lon, zoom); -} -#endif - -#ifdef USE_PGSQL -#ifdef USE_MYSQL -#error ONLY one of USE_MYSQL and USE_PGSQL should be defined -#endif - -#include -#include - -Datum -maptile_for_point(PG_FUNCTION_ARGS) -{ - double lat = PG_GETARG_INT64(0) / 10000000.0; - double lon = PG_GETARG_INT64(1) / 10000000.0; - int zoom = PG_GETARG_INT32(2); - - PG_RETURN_INT32(internal_maptile_for_point(lat, lon, zoom)); + PG_RETURN_INT32((x << zoom) | y); } PG_FUNCTION_INFO_V1(maptile_for_point); @@ -93,5 +34,3 @@ PG_FUNCTION_INFO_V1(maptile_for_point); #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif - -#endif diff --git a/db/functions/quadtile.c b/db/functions/quadtile.c index 29758edc6..748e0b9aa 100644 --- a/db/functions/quadtile.c +++ b/db/functions/quadtile.c @@ -1,54 +1,5 @@ -#ifndef USE_MYSQL -#ifndef USE_PGSQL -#error One of USE_MYSQL or USE_PGSQL must be defined -#endif -#endif - #include #include - -#ifdef USE_MYSQL -#ifdef USE_PGSQL -#error ONLY one of USE_MYSQL and USE_PGSQL should be defined -#endif - -#include -#include -#include -#include - -my_bool tile_for_point_init(UDF_INIT *initid, UDF_ARGS *args, char *message) -{ - if ( args->arg_count != 2 || - args->arg_type[0] != INT_RESULT || - args->arg_type[1] != INT_RESULT ) - { - strcpy( message, "Your tile_for_point arguments are bogus!" ); - return 1; - } - - return 0; -} - -void tile_for_point_deinit(UDF_INIT *initid) -{ - return; -} - -long long tile_for_point(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) -{ - long long lat = *(long long *)args->args[0]; - long long lon = *(long long *)args->args[1]; - - return xy2tile(lon2x(lon / 10000000.0), lat2y(lat / 10000000.0)); -} -#endif - -#ifdef USE_PGSQL -#ifdef USE_MYSQL -#error ONLY one of USE_MYSQL and USE_PGSQL should be defined -#endif - #include #include @@ -72,5 +23,3 @@ PG_FUNCTION_INFO_V1(tile_for_point); * * (without all the *s) */ - -#endif diff --git a/db/functions/xid_to_int4.c b/db/functions/xid_to_int4.c index 6863dfaca..d654bf269 100644 --- a/db/functions/xid_to_int4.c +++ b/db/functions/xid_to_int4.c @@ -1,14 +1,3 @@ -#ifndef USE_MYSQL -#ifndef USE_PGSQL -#error One of USE_MYSQL or USE_PGSQL must be defined -#endif -#endif - -#ifdef USE_PGSQL -#ifdef USE_MYSQL -#error ONLY one of USE_MYSQL and USE_PGSQL should be defined -#endif - #include #include @@ -26,5 +15,3 @@ int xid_to_int4(TransactionId xid) * * (without all the *s) */ - -#endif diff --git a/lib/migrate.rb b/lib/migrate.rb index e30d071cd..7549add2a 100644 --- a/lib/migrate.rb +++ b/lib/migrate.rb @@ -42,170 +42,88 @@ module ActiveRecord end end - if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) - class MysqlAdapter - alias_method :old_native_database_types, :native_database_types - - def native_database_types - types = old_native_database_types - types[:bigint] = { :name => "bigint", :limit => 20 } - types[:double] = { :name => "double" } - types[:integer_pk] = { :name => "integer DEFAULT NULL auto_increment PRIMARY KEY" } - types[:bigint_pk] = { :name => "bigint(20) DEFAULT NULL auto_increment PRIMARY KEY" } - types[:bigint_pk_64] = { :name => "bigint(64) DEFAULT NULL auto_increment PRIMARY KEY" } - types[:bigint_auto_64] = { :name => "bigint(64) DEFAULT NULL auto_increment" } - types[:bigint_auto_11] = { :name => "bigint(11) DEFAULT NULL auto_increment" } - types[:bigint_auto_20] = { :name => "bigint(20) DEFAULT NULL auto_increment" } - types[:four_byte_unsigned] = { :name=> "integer unsigned" } - types[:inet] = { :name=> "integer unsigned" } - - enumerations.each do |e,v| - types[e.to_sym]= { :name => "enum('#{v.join '\',\''}')" } - end - - types - end - - def change_column(table_name, column_name, type, options = {}) - unless options_include_default?(options) - options[:default] = select_one("SHOW COLUMNS FROM #{table_name} LIKE '#{column_name}'")["Default"] - - unless type == :string or type == :text - options.delete(:default) if options[:default] = ""; - end - end - - change_column_sql = "ALTER TABLE #{table_name} CHANGE #{column_name} #{column_name} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}" - add_column_options!(change_column_sql, options) - execute(change_column_sql) - end - - def myisam_table - return { :id => false, :force => true, :options => "ENGINE=MyIsam" } - end - - def innodb_table - return { :id => false, :force => true, :options => "ENGINE=InnoDB" } - end - - def innodb_option - return "ENGINE=InnoDB" - end - - def change_engine (table_name, engine) - execute "ALTER TABLE #{table_name} ENGINE = #{engine}" - end - - def add_fulltext_index (table_name, column) - execute "CREATE FULLTEXT INDEX `#{table_name}_#{column}_idx` ON `#{table_name}` (`#{column}`)" - end - - def enumerations - @enumerations ||= Hash.new - end - - def create_enumeration (enumeration_name, values) - enumerations[enumeration_name] = values - end - - def drop_enumeration (enumeration_name) - enumerations.delete(enumeration_name) - end + class PostgreSQLAdapter + alias_method :old_native_database_types, :native_database_types + + def native_database_types + types = old_native_database_types + types[:double] = { :name => "double precision" } + types[:integer_pk] = { :name => "serial PRIMARY KEY" } + types[:bigint_pk] = { :name => "bigserial PRIMARY KEY" } + types[:bigint_pk_64] = { :name => "bigserial PRIMARY KEY" } + types[:bigint_auto_64] = { :name => "bigint" } #fixme: need autoincrement? + types[:bigint_auto_11] = { :name => "bigint" } #fixme: need autoincrement? + types[:bigint_auto_20] = { :name => "bigint" } #fixme: need autoincrement? + types[:four_byte_unsigned] = { :name => "bigint" } # meh + types[:inet] = { :name=> "inet" } + + enumerations.each_key do |e| + types[e.to_sym]= { :name => e } + end + + types + end - def alter_primary_key(table_name, new_columns) - execute("alter table #{table_name} drop primary key, add primary key (#{new_columns.join(',')})") - end + def myisam_table + return { :id => false, :force => true, :options => ""} + end - def interval_constant(interval) - "'#{interval}'" - end + def innodb_table + return { :id => false, :force => true, :options => ""} end - end - if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) - class PostgreSQLAdapter - alias_method :old_native_database_types, :native_database_types - - def native_database_types - types = old_native_database_types - types[:double] = { :name => "double precision" } - types[:integer_pk] = { :name => "serial PRIMARY KEY" } - types[:bigint_pk] = { :name => "bigserial PRIMARY KEY" } - types[:bigint_pk_64] = { :name => "bigserial PRIMARY KEY" } - types[:bigint_auto_64] = { :name => "bigint" } #fixme: need autoincrement? - types[:bigint_auto_11] = { :name => "bigint" } #fixme: need autoincrement? - types[:bigint_auto_20] = { :name => "bigint" } #fixme: need autoincrement? - types[:four_byte_unsigned] = { :name => "bigint" } # meh - types[:inet] = { :name=> "inet" } - - enumerations.each_key do |e| - types[e.to_sym]= { :name => e } - end - - types - end + def innodb_option + return "" + end - def myisam_table - return { :id => false, :force => true, :options => ""} - end + def change_engine (table_name, engine) + end - def innodb_table - return { :id => false, :force => true, :options => ""} - end + def add_fulltext_index (table_name, column) + execute "CREATE INDEX #{table_name}_#{column}_idx on #{table_name} (#{column})" + end - def innodb_option - return "" - end + def enumerations + @enumerations ||= Hash.new + end - def change_engine (table_name, engine) - end + def create_enumeration (enumeration_name, values) + enumerations[enumeration_name] = values + execute "create type #{enumeration_name} as enum ('#{values.join '\',\''}')" + end - def add_fulltext_index (table_name, column) - execute "CREATE INDEX #{table_name}_#{column}_idx on #{table_name} (#{column})" - end + def drop_enumeration (enumeration_name) + execute "drop type #{enumeration_name}" + enumerations.delete(enumeration_name) + end - def enumerations - @enumerations ||= Hash.new - end + def alter_primary_key(table_name, new_columns) + execute "alter table #{table_name} drop constraint #{table_name}_pkey; alter table #{table_name} add primary key (#{new_columns.join(',')})" + end - def create_enumeration (enumeration_name, values) - enumerations[enumeration_name] = values - execute "create type #{enumeration_name} as enum ('#{values.join '\',\''}')" - end + def interval_constant(interval) + "'#{interval}'::interval" + end - def drop_enumeration (enumeration_name) - execute "drop type #{enumeration_name}" - enumerations.delete(enumeration_name) - end + def add_index(table_name, column_name, options = {}) + column_names = Array(column_name) + index_name = index_name(table_name, :column => column_names) - def alter_primary_key(table_name, new_columns) - execute "alter table #{table_name} drop constraint #{table_name}_pkey; alter table #{table_name} add primary key (#{new_columns.join(',')})" + if Hash === options # legacy support, since this param was a string + index_type = options[:unique] ? "UNIQUE" : "" + index_name = options[:name] || index_name + index_method = options[:method] || "BTREE" + else + index_type = options end - def interval_constant(interval) - "'#{interval}'::interval" + quoted_column_names = column_names.map { |e| quote_column_name(e) } + if Hash === options and options[:lowercase] + quoted_column_names = quoted_column_names.map { |e| "LOWER(#{e})" } end + quoted_column_names = quoted_column_names.join(", ") - def add_index(table_name, column_name, options = {}) - column_names = Array(column_name) - index_name = index_name(table_name, :column => column_names) - - if Hash === options # legacy support, since this param was a string - index_type = options[:unique] ? "UNIQUE" : "" - index_name = options[:name] || index_name - index_method = options[:method] || "BTREE" - else - index_type = options - end - - quoted_column_names = column_names.map { |e| quote_column_name(e) } - if Hash === options and options[:lowercase] - quoted_column_names = quoted_column_names.map { |e| "LOWER(#{e})" } - end - quoted_column_names = quoted_column_names.join(", ") - - execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} USING #{index_method} (#{quoted_column_names})" - end + execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} USING #{index_method} (#{quoted_column_names})" end end end