Re: [capistrano] database synchronization on Non-Rails apps

2011-04-02 Thread Donovan Bray
You need a change management system for your database schema. You are thinking 
in terms of development ease but truly the difficulty lies in preserving 
production data; there's no way just copying the schema will ever suffice. The 
moment you need to do an alter table your sunk. You can't be dropping tables 
just so you can create the schema you need as you can during development. As 
development marches on you will be faced with situations that need to modify 
data that won't need to modify schema.  You need to manage those changes as 
well. 

Rails has the best scheme I've seen and I would guess many frameworks have 
copied it; what are you writing your app in?

A simpler method but requires you to be very deliberate in the queries you 
write is a pattern that coppermine gallery uses; and probably many other php 
apps.  

Consists of two files. An initial SQL file that is designed to create a new 
schema (seed).  The second is for updating an existing one (update). (you may 
only need update if you aren't creating new databases all the time)

When you make a change to you schema you make it to both files being mindful of 
the context they are run. 

The layout of the files is the same; a series of properly terminated queries; 
the trick is this file is read as a string; split on those terminations and run 
one statement at a time; if it succeeds print "ok"; if it doesn't print 
"already done";

That's where the deliberate part comes in; since you need to write the queries 
to be idempotent; ie you should write the query such that you can run it any 
number of times but it won't damage anything after it's initial run. Since 
failure is expected; obviously you need to test what you add to the files 
really well. 

Check the SQL directory in coppermine to see what I mean. 

Lastly RUNNING your db schema mgmt  system IS in the capistrano perview.  But 
the actual details and implementation of that system is in the perview of your 
application or application framework. So a forum dedicated to whatever 
framework you are building your app in would be a better place to get advice 
for this issue. 

On Apr 2, 2011, at 1:05 PM, mem  wrote:

> On 02-04-2011 19:25, Lee Hambley wrote:
>> 
>> Is this correct?
>> 
>> Correct!
>> 
>> (Will reply in depth when I'm home) 
> 
> Thanks.
> 
> Well, one question is prevailing. 
> 
> I've created a git hook that executes a mysqldump to the schema and saves it 
> somewhere on a place where the git can reach.
> 
> The git hook seems to be a nice option, because since Capistrano will deploy 
> committed files, I can rest assured that it will deploy (my last local schema 
> to a file).
> 
> After reading a bit more, I now understand that this seems to not suffice. 
> 
> I mean: "Great I have a sql file with my last schema on the remote server". 
> Now what? 
> I still need a way to apply that schema to the remote database.
> 
> If I'm thinking right, could Capistrano help me archiving this last step ?
> -- 
> * You received this message because you are subscribed to the Google Groups 
> "Capistrano" group.
> * To post to this group, send email to capistrano@googlegroups.com
> * To unsubscribe from this group, send email to 
> capistrano+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/capistrano?hl=en

-- 
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to capistrano@googlegroups.com
* To unsubscribe from this group, send email to 
capistrano+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Re: [capistrano] database synchronization on Non-Rails apps

2011-04-02 Thread mem

On 02-04-2011 19:25, Lee Hambley wrote:


Is this correct?


Correct!

(Will reply in depth when I'm home)


Thanks.

Well, one question is prevailing.

I've created a git hook that executes a mysqldump to the schema and 
saves it somewhere on a place where the git can reach.


The git hook seems to be a nice option, because since Capistrano will 
deploy committed files, I can rest assured that it will deploy (my last 
local schema to a file).


After reading a bit more, I now understand that this seems to not suffice.

I mean: "Great I have a sql file with my last schema on the remote 
server". Now what?

I still need a way to apply that schema to the remote database.

If I'm thinking right, could Capistrano help me archiving this last step ?

--
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to capistrano@googlegroups.com
* To unsubscribe from this group, send email to 
capistrano+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Re: [capistrano] database synchronization on Non-Rails apps

2011-04-02 Thread Lee Hambley
>
> Is this correct?
>

Correct!

(Will reply in depth when I'm home)

Sent from my  iPhone

-- 
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to capistrano@googlegroups.com
* To unsubscribe from this group, send email to 
capistrano+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Re: [capistrano] database synchronization on Non-Rails apps

2011-04-02 Thread mem

On 02-04-2011 16:55, mem wrote:


Can I exclude .rb files to be deployed ? If so, what would the command be?

Do I need to exclude .git files or, isn't necessary?

Let me guess, since we are using remote_cache and we are using a 
subversion system, the only thing we have to do is to, take out from our 
subversion control, the files and folders that we don't want, because, 
deploy will, on this case, only deploy the committed changes.


Is this correct?

--
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to capistrano@googlegroups.com
* To unsubscribe from this group, send email to 
capistrano+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Re: [capistrano] database synchronization on Non-Rails apps

2011-04-02 Thread mem

On 01-04-2011 13:49, Lee Hambley wrote:

Márcio,

Where can I see some examples about mysql syncronization for a
non-rails application?


Rails uses a migrations syntax, in a nut-shell, this works like 
001-create-table-one.rb, 002-create-table-two.rb, 
003-change-table-one.rb, each one is tracked, and if `003` hasn't been 
run, it gets run… that's all there is to it, they don't preserve data 
(unless you write them carefully) and it's not a MySQL feature or 
something. The Rails method works across databes… supporting MySQL, 
PostgreSQL, etc.. it's a pretty naïve implementation, but it works well.


Perhaps your framework gives you something, if not you might want to 
look at `cap web:disable` and `cap web:enable` - to (also naïeve) 
tasks for copying a template "maintenance" page into place whilst you 
do work that requires some downtime (or a few minutes on a quiet DB)


Well, I'm not sure if this helps us somehow, but I've put the database 
schema on a file, using a git hook.
Hopping that, by doing this, I can have my local and remote database 
syncronized (not the data, only schema) and that, I will not need 
Capistrano there.

Not sure of this, since I've nothing tested yet.




Regarding assets between deploys, there's a variable called 
:shared_children - you set it to an array of the `shared between 
release` directories, this defaults to something like log, config, 
tmp, etc - these are documented here: 
https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy.rb#L50


Put whatever directories you need in here, then at first/early deploy 
time, make sure your assets are in :deploy_to/shared/whatever-directory/


I don't recall writing anything about assets. (my English is so poor 
that if someone uses synonymous, without pointing them out, I will 
probably not get (anyway, that's my issue).
But, as a bonus, I now understand what shared directory means! 'shared 
between release' (Ignoring my lack of knowledge in English matters, and 
if I'm allowed I would called it "preserve").


Anyway, since I use a :remote_cache deploy, I'm deploying only the 
committed files.
This being said, I probably don't need to use the shared directory to 
deal with "assets". (correct?).



If all the above is correct, two questions - taking that I'm using 
remote_cache method:


Can I exclude .rb files to be deployed ? If so, what would the command be?

Do I need to exclude .git files or, isn't necessary?


Thanks a lot,
Márcio

--
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to capistrano@googlegroups.com
* To unsubscribe from this group, send email to 
capistrano+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Re: [capistrano] database synchronization on Non-Rails apps

2011-04-01 Thread Lee Hambley
Márcio,

Where can I see some examples about mysql syncronization for a non-rails
> application?


Rails uses a migrations syntax, in a nut-shell, this works like
001-create-table-one.rb, 002-create-table-two.rb, 003-change-table-one.rb,
each one is tracked, and if `003` hasn't been run, it gets run… that's all
there is to it, they don't preserve data (unless you write them carefully)
and it's not a MySQL feature or something. The Rails method works across
databes… supporting MySQL, PostgreSQL, etc.. it's a pretty naïve
implementation, but it works well.

Perhaps your framework gives you something, if not you might want to look at
`cap web:disable` and `cap web:enable` - to (also naïeve) tasks for copying
a template "maintenance" page into place whilst you do work that requires
some downtime (or a few minutes on a quiet DB)

Regarding assets between deploys, there's a variable called :shared_children
- you set it to an array of the `shared between release` directories, this
defaults to something like log, config, tmp, etc - these are documented
here:
https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy.rb#L50

Put whatever directories you need in here, then at first/early deploy time,
make sure your assets are in :deploy_to/shared/whatever-directory/

Hope that helps, at least a little (focused questions are more likely to
elicit answers out of reluctant mailing list subscribers!).

-- 
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to capistrano@googlegroups.com
* To unsubscribe from this group, send email to 
capistrano+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en