diff --git a/tracks/db/migrate/2_add_user_id.rb b/tracks/db/migrate/2_add_user_id.rb index 0f5a8688..8453d47c 100644 --- a/tracks/db/migrate/2_add_user_id.rb +++ b/tracks/db/migrate/2_add_user_id.rb @@ -1,8 +1,8 @@ class AddUserId < ActiveRecord::Migration def self.up - add_column :contexts, :user_id, :integer, :null => false - add_column :projects, :user_id, :integer, :null => false - add_column :todos, :user_id, :integer, :null => false + add_column "contexts", "user_id", :integer, :default => 1 + add_column "projects", "user_id", :integer, :default => 1 + add_column "todos", "user_id", :integer, :default => 1 execute "UPDATE 'contexts' SET 'user_id' = 1;" execute "UPDATE 'projects' SET 'user_id' = 1;" execute "UPDATE 'todos' SET 'user_id' = 1;" diff --git a/tracks/db/migrate/3_created_at.rb b/tracks/db/migrate/3_created_at.rb index fb12b97f..47fa00f7 100644 --- a/tracks/db/migrate/3_created_at.rb +++ b/tracks/db/migrate/3_created_at.rb @@ -1,9 +1,12 @@ class CreatedAt < ActiveRecord::Migration + # Current bug in Rails that prevents rename_column working in SQLite + # if the column names use symbols instead of strings. + # def self.up - rename_column :todos, :created, :created_at + rename_column "todos", "created", "created_at" end def self.down - rename_column :todos, :created_at, :created + rename_column "todos", "created_at", "created" end end diff --git a/tracks/db/schema.rb b/tracks/db/schema.rb index fbcbca42..205d7eb1 100644 --- a/tracks/db/schema.rb +++ b/tracks/db/schema.rb @@ -5,10 +5,10 @@ ActiveRecord::Schema.define(:version => 5) do create_table "contexts", :force => true do |t| - t.column "name", :string, :null => false - t.column "position", :integer, :null => false + t.column "name", :string, :default => "", :null => false t.column "hide", :boolean, :default => false - t.column "user_id", :integer, :null => false + t.column "position", :integer, :null => false + t.column "user_id", :integer, :default => 1 end create_table "notes", :force => true do |t| @@ -20,30 +20,30 @@ ActiveRecord::Schema.define(:version => 5) do end create_table "projects", :force => true do |t| - t.column "name", :string, :null => false + t.column "name", :string, :default => "", :null => false t.column "position", :integer, :null => false t.column "done", :boolean, :default => false - t.column "user_id", :integer, :null => false + t.column "user_id", :integer, :default => 1 t.column "description", :text, :default => "" end create_table "todos", :force => true do |t| - t.column "context_id", :integer, :null => false - t.column "project_id", :integer - t.column "description", :string, :null => false + t.column "context_id", :integer, :limit => 11, :default => 0, :null => false + t.column "description", :string, :limit => 100, :default => "", :null => false t.column "notes", :text - t.column "done", :boolean, :default => false, :null => false - t.column "created_at", :datetime + t.column "done", :boolean, :default => false + t.column "created_at", :datetime, :null => false t.column "due", :date t.column "completed", :datetime - t.column "user_id", :integer, :null => false + t.column "project_id", :integer, :limit => 11 + t.column "user_id", :integer, :default => 1 end create_table "users", :force => true do |t| - t.column "login", :string, :limit => 80, :null => false - t.column "password", :string, :limit => 40, :null => false + t.column "login", :string, :limit => 80 + t.column "password", :string, :limit => 40 t.column "word", :string - t.column "is_admin", :boolean, :default => false, :null => false + t.column "is_admin", :boolean, :default => false end end diff --git a/tracks/doc/CHANGELOG b/tracks/doc/CHANGELOG index 56d96f8a..ce0f93d8 100644 --- a/tracks/doc/CHANGELOG +++ b/tracks/doc/CHANGELOG @@ -4,7 +4,7 @@ * Author: bsag (http://www.rousette.org.uk/) * Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens, Luke Melia, John Leonard (for great installation tutorials on Windows XP) * Version: 1.03 -* Copyright: (cc) 2004-2005 rousette.org.uk +* Copyright: (cc) 2004-2006 rousette.org.uk * License: GNU GPL Main project site: http://www.rousette.org.uk/projects/ @@ -34,6 +34,7 @@ Wiki (deprecated - please use Trac): http://www.rousette.org.uk/projects/wiki/ 16. Got rid of the 'fresh actions' box on the home page. When you create a new action, it is now automatically inserted (via the magic of Ajax and RJS templates) at the bottom of the correct context box. 17. The next action count badge is now dynamically updated whenever you add or delete a next action, so that you don't have to refresh to see the count updated. 18. Validation errors are now reported in a status box (just above the new next action form). +19. There's a rake task (upgrade_sqlite_db) which allows you to safely upgrade databases created with version 1.03, afterwhich you can run rake migrate to complete the process. From there, rake migrate should work OK. == Version 1.03 diff --git a/tracks/doc/README_FOR_APP b/tracks/doc/README_FOR_APP index 9408e00c..bbe5a52d 100644 --- a/tracks/doc/README_FOR_APP +++ b/tracks/doc/README_FOR_APP @@ -4,7 +4,7 @@ * Author: bsag (http://www.rousette.org.uk/) * Contributors: Nicholas Lee, Lolindrath, Jim Ray, Arnaud Limbourg, Timothy Martens, Luke Melia, John Leonard (for great installation tutorials on Windows XP) * Version: 1.031 -* Copyright: (cc) 2004-2005 rousette.org.uk +* Copyright: (cc) 2004-2006 rousette.org.uk * License: GNU GPL Trac (for bug reports and feature requests): http://dev.rousette.org.uk/report/6 @@ -17,13 +17,15 @@ While fully usable for everyday use, Tracks is still a work in progress. Make su == Installation (for trunk version only) -Before you start, you need to make sure that you have Ruby 1.8.2, Rails 0.14.3, and Redcloth 3.0.3. By far the easiest way to get these installed is using gems (see instructions on getting gems here http://wiki.rubyonrails.com/rails/show/GemRails). You also need some kind of database. MySQL is probably the most popular, but it's also easy to use PostgreSQL or SQLite. If you have Mac OS X Tiger, you already have Ruby 1.8.2 and SQLite3 installed, so all you need to do after installing Rails and Redcloth is to install the sqlite3-ruby gem (1.1.0). See http://dev.rousette.org.uk/wiki/Tracks/Install for more details on installing all the necessary components on all the supported platforms. +Before you start, you need to make sure that you have Ruby 1.8.2 installed. Rails 1.0 and RedCloth are now included in the vendor directory of the distribution, so you don't need to install them yourself. You also need some kind of database. MySQL is probably the most popular, but it's also easy to use PostgreSQL or SQLite. If you have Mac OS X Tiger, you already have Ruby 1.8.2 and SQLite3 installed, so all you need to do after installing Rails and Redcloth is to install the sqlite3-ruby gem (1.1.0). See http://dev.rousette.org.uk/wiki/Tracks/Install for more details on installing all the necessary components on all the supported platforms. === New users +==== MySQL + In the following, I'm assuming that you're using MySQL and the built-in WEBrick server. See the sections below for addtional instructions on using other databases and servers. -* Unzip tracks_1_031.zip somewhere in your home folder ( e.g. /Users/yourusername/Sites). +* Unzip tracks_1_04.zip somewhere in your home folder ( e.g. /Users/yourusername/Sites). * Make a database for which you have full access rights. e.g. assuming that you are using MySQL, and that you want to call your database tracks, at the command line: mysql -uroot -p @@ -39,13 +41,13 @@ In the following, I'm assuming that you're using MySQL and the built-in WEBrick cd /PATHTO/TRACKS rake setup_tracks -* The next task you need to run is 'migrate': this will populate the database you've made with the correct table schemas. It also adds a table 'schema_info', which keeps track of which version you are using. This means that you can potentially also revert back to an earlier schema. Use it as follows at the command line: +* Run 'rake setup_tracks', which will copy all the files and directories with *.tmpl extensions and removes the extension. It ignores any files or directories that you've already converted, so it's safe to run it when you're upgrading: cd /PATHTO/TRACKS rake migrate * Check over the file config/settings.yml, and make sure that the settings are to your liking. -* If you'd also like some example data to play with, you can import it from tracks_1.031_content.sql (in tracks/db). You don't have to use the example data, but if you don't, you'll need to visit http://YOURURL/contexts first to add a few contexts before you add any next actions. Note that no users are provided in the content file, so you'll need to visit the signup page (http://YOURURL/signup) to create some users. +* If you'd also like some example data to play with, you can import it from tracks_1.04_content.sql (in tracks/db). You don't have to use the example data, but if you don't, you'll need to visit http://YOURURL/contexts first to add a few contexts before you add any next actions. Note that no users are provided in the content file, so you'll need to visit the signup page (http://YOURURL/signup) to create some users. * Check the shebang lines of the public/dispatch.* files and all the files in the script directory. They are set to #!/usr/bin/env ruby by default. This should work for all *nix based setups (Linux or Mac OS X), but Windows users will probably have to change it. Try this command at the command line, run inside the Tracks directory: ruby -i.bak -pe 'gsub!("#!/usr/bin/env ruby", "#!c:/ruby/bin/ruby")' public/dispatch.* script/* * Run the following command at your command line (Important: If you already have an application running on WEBrick (Tracks or anything else), make sure that you stop the server, or run Tracks on a different port using the --port option): @@ -55,57 +57,58 @@ In the following, I'm assuming that you're using MySQL and the built-in WEBrick * In a browser, go to http://0.0.0.0:3000/signup. This will allow you to choose a username and password for the admin user. Thereafter, anyone else trying to access /signup will get a message that they are not allowed to sign up, and are given your email address to contact for permission. When you are logged in as the admin user, you can visit /signup to sign up additional users (who will not be able to view any of your next actions, contexts, projects or notes, but can set up their own separate tasks), and visit /login to login yourself. * Have fun! +==== SQLite/SQLite3 + +The instructions are the same as those for MySQL above, except that you don't need to create the database first before running 'rake migrate'. All you need to do is to give the file name of the database you'd like to create in database.yml. e.g. + adapter: sqlite3 + database: /Users/YOURUSERNAME/Sites/tracks/db/tracks_104.db +Then cd into the db directory and run rake migrate. This should create the database for you, and populate it with the correct tables. + === Upgrading from Tracks 1.03 ==== MySQL or Postgresql -* For safety, rename your current Tracks directory to 'tracks-old' or something similar, and if you are able, create a new database for the new version. If you can't create a new database, delete the contents and tables in your old one MAKING SURE THAT YOU HAVE BACKED UP YOUR DATABASE FIRST. +* For safety, rename your current Tracks directory to 'tracks-old' or something similar. +* The 'rake migrate' script should be able to update your database tables with the contents in place, but it's very important to make a MySQL dump of both the contents and tables before you go any further. KEEP THIS BACKUP IN A SAFE PLACE IN CASE YOU HAVE TO REVERT TO IT. * Make sure that you check settings.yml.tmpl for new info, and add any new fields to your settings.yml file. Some new settings have been added in the past couple of versions, and not having the correct settings is a common cause of errors. * Before you do anything else, BACK UP YOUR DATABASE (tables and content). Then make a separate export of the contents only (assuming that you want to move your data to the new version.) -* The file tracks/Rakefile contains various useful tasks you can run. The first one you need to run copies all the files and directories with *.tmpl extensions and removes the extension. It ignores any files or directories that you've already converted, so it's safe to run it when you're upgrading: +* Run 'rake setup_tracks', which will copy all the files and directories with *.tmpl extensions and removes the extension. It ignores any files or directories that you've already converted, so it's safe to run it when you're upgrading: cd /PATHTO/TRACKS rake setup_tracks -* If you are using MySQL or Postgresql, you can use the new Rakefile rake migrate task to update your tables. At your command line: +* If you are using MySQL or Postgresql, you can use the rake migrate task to update your tables. At your command line: cd /PATHTO/TRACKS rake migrate * If this process reports errors that you can't fix, you'll need to adapt the instructions for manually loading the schema, given below for SQLite (schemas are also provided for MySQL and Postgresql). -* Import your old contents, and check that it looks sensible. In particular, check that the 'user_id' field in the todos, contexts and projects tables have the value of '1' (i.e. they are owned by your admin user, who should have an id of 1). +* Check that the contents of your database look sensible. In particular, check that the 'user_id' field in the todos, contexts and projects tables have the value of '1' (i.e. they are owned by your admin user, who should have an id of 1). * Check the shebang lines of the public/dispatch.* files and all the files in the script directory. They are set to #!/usr/bin/env ruby by default. This should work for all *nix based setups (Linux or Mac OS X), but Windows users will probably have to change it. Try this command at the command line, run inside the Tracks directory: ruby -i.bak -pe 'gsub!("#!/usr/bin/env ruby", "#!c:/ruby/bin/ruby")' public/dispatch.* script/* -* From here, follow the remaining steps for new users above to start the server. Don't forget that if you've deleted your users table, you'll need to re-create your users via /signup. Signup is now at http://0.0.0.0:3000/signup, and login at http://0.0.0.0:3000/login. +* From here, follow the remaining steps for new users above to start the server. You might find that your previous username and password doesn't work, in which case you'll have to go into your database, delete all the users, and then re-create your users via /signup. Signup is now at http://0.0.0.0:3000/signup, and login at http://0.0.0.0:3000/login. ==== SQLite or SQLite3 -* For safety, rename your current Tracks directory to 'tracks-old' or something similar, and if you are able, create a new database for the new version. If you can't create a new database, delete the contents and tables in your old one MAKING SURE THAT YOU HAVE BACKED UP YOUR DATABASE FIRST. +* For safety, rename your current Tracks directory to 'tracks-old' or something similar (making sure that you keep your old database safe), create a new directory for the new version. +* Copy (NOT MOVE!) your old database into the new tracks/db directory. * Make sure that you check settings.yml.tmpl for new info, and add any new fields to your settings.yml file. Some new settings have been added in the past couple of versions, and not having the correct settings is a common cause of errors. -* The file tracks/Rakefile contains various useful tasks you can run. The task 'setup_tracks' copies all the files and directories with *.tmpl extensions and removes the extension. It ignores any files or directories that you've already converted, so it's safe to run it when you're upgrading: +* Run 'rake setup_tracks', which will copy all the files and directories with *.tmpl extensions and removes the extension. It ignores any files or directories that you've already converted, so it's safe to run it when you're upgrading: cd /PATHTO/TRACKS rake setup_tracks -* If you're using SQLite/SQLite3, you'll need to create a new database and import the new schema (db/tracks_1.031_sqlite.sql), and then import your old contents. You need to check that the new fields have sensible contents. In particular, check that the 'user_id' field in the todos, contexts and projects tables have the value of '1' (i.e. they are owned by your admin user, who should have an id of 1). Use db/tracks_1.0.3_content.sql as a guide for the correct syntax. -sure that you get a fresh copy, or you'll get errors. +* The rake task upgrade_sqlite_db.rake (in tracks/lib/tasks) will help you to upgrade your database before running 'rake migrate' to make the appropriate changes to the tables. In lines 4-6 of that file, you'll find some variables (old_db, new_db and cmd) that you'll need to change appropriately for your setup. old_db is the filename of your old version 1.03 database, new_db is the filename you'd like to give to the new database, and cmd is sqlite or sqlite3 depending on which verison you're using. +* Save the file after making the changes, then - in the root of your tracks directory - issue the command rake upgrade_sqlite_db. You should get a message that your new db has been created, and some temporary files created. +You need to check the new database to make sure that it has sensible contents. In particular, check that the 'user_id' field in the todos, contexts and projects tables have the value of '1' (i.e. they are owned by your admin user, who should have an id of 1). +* Edit config/database.yml with the name of your new database file. +* Run 'rake migrate'. This should update the tables to the new format. * Check that the path to Ruby is correct in the tracks/public/dispatch.* files, and also /script/server. The default (#!/usr/bin/ruby) is fine for Mac OS X Tiger, but if you've installed Ruby yourself in /usr/local/bin, you'll need to change it. * From here, follow the remaining steps for new users above to start the server. Don't forget that if you've deleted your users table, you'll need to re-create your users via /signup. Signup is now at http://0.0.0.0:3000/signup, and login at http://0.0.0.0:3000/login. -== Using databases other than MySQL - -Rick Bradley kindly converted the MySQL schema for Tracks to Postgresql format, so I was able to use that as a model for the new version - see tracks/db/tracks_1.031_postgres.sql. There's also a schema for SQLite/SQLite3 (tracks/db/tracks_1.031_sqlite.sql). Remember that you'll also need to change the adapter line in database.yml: - adapter: postgresql - -or for SQLite3: - adapter: sqlite3 - database: /fullpathto/db/yoursqlite.db - -If you're using SQLite 2.x, substitute 'sqlite' for 'sqlite3' above. Also note that those are the only lines you need for SQLite; the username, password, database and host lines are not necessary. - == Other servers -WEBrick is the easiest server to get working to test out Tracks, and will be fine if you have Tracks installed on your own machine. One nice feature in Rails 0.13.1 is that WEBrick runs by default on the IP address 0.0.0.0, which means that you can access it via 127.0.0.1 when you are on the same machine, or via the external IP address of the machine running Tracks, so long as you can access the network of that machine from your current location. However, it is possible to use other servers, and the new re-writing rules of Rails 0.13.1 ('Routes' in environment/routes.rb) mean that very little configuration is needed. +WEBrick is the easiest server to get working to test out Tracks, and will be fine if you have Tracks installed on your own machine. One nice feature in Rails 0.13.1 is that WEBrick runs by default on the IP address 0.0.0.0, which means that you can access it via 127.0.0.1 when you are on the same machine, or via the external IP address of the machine running Tracks, so long as you can access the network of that machine from your current location. However, it is possible to use other servers, and the new re-writing rules of Rails 0.13.1 ('Routes' in environment/routes.rb) mean that very little configuration is needed. With Rails 1.0, if you have lighttpd installed, running script/server starts lighttpd instead of WEBrick, creating the appropriate lighttpd.conf file automatically. === Apache diff --git a/tracks/lib/tasks/migrate.rake b/tracks/lib/tasks/migrate.rake deleted file mode 100644 index 22bb4d77..00000000 --- a/tracks/lib/tasks/migrate.rake +++ /dev/null @@ -1,4 +0,0 @@ -desc "Migrate the database according to the migrate scripts in db/migrate (only supported on PG/MySQL). A specific version can be targetted with VERSION=x" -task :migrate => :environment do - ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/db/migrate/', ENV["VERSION"] ? ENV["VERSION"].to_i : nil) -end \ No newline at end of file diff --git a/tracks/lib/tasks/upgrade_sqlite_db.rake b/tracks/lib/tasks/upgrade_sqlite_db.rake new file mode 100644 index 00000000..06922e6e --- /dev/null +++ b/tracks/lib/tasks/upgrade_sqlite_db.rake @@ -0,0 +1,40 @@ +desc "Updates sqlite/sqlite3 databases created under Tracks 1.03 to the format required for Tracks 1.04. After this is done, you should be able to keep up to date with changes in the schema by running rake migrate." +task :upgrade_sqlite_db => :environment do + # Change the three lines below appropriately for your setup + old_db = "tracks_103.db" + new_db = "tracks_104.db" + cmd = "sqlite3" + replace_string = "update todos set done='f' where done=0;\nupdate todos set done='t' where done=1;\nupdate contexts set hide='f' where hide=0;\nupdate contexts set hide='t' where hide=1;\nupdate projects set done='f' where done=0;\nupdate projects set done='t' where done=1;\nCREATE TABLE 'schema_info' (\n 'version' INTEGER default NULL\n);\nINSERT INTO \"schema_info\" VALUES(1);\nCOMMIT;" + + # cd to the db directory + cd("db") do + # Dump the old db into the temp file and replace the tinyints with booleans + `#{cmd} #{old_db} .dump | sed "s/tinyint(4) NOT NULL default '0'/boolean default 'f'/" > temp.sql` + # Create a second sqldump file for writing + sqldump = File.open("temp2.sql", "w+") + File.open("temp.sql") do |file| + file.each_line do |line| + # If COMMIT is on the line, insert the replace string + # else just write the line back in + # This effectively replaces COMMIT with the replace string + if /COMMIT/ =~ line + sqldump.write replace_string + else + sqldump.write line + end + end + sqldump.close + end + + # Read the second dump back in to a new db + system "#{cmd} #{new_db} < temp2.sql" + puts "Created the a new database called #{new_db}." + # Clean up the temp files + rm("temp.sql") + rm("temp2.sql") + puts "Temporary files cleaned up." + end + + # rake migrate + puts "Now check the database and run 'rake migrate' in the root of your Tracks installation." +end \ No newline at end of file