Re: Adding stored procedures

2018-04-19 Thread Larry Martell
There are django-mssql and django_pyodbc but I was never able to get
either of those to work for me. I ended up using odbc - I couldn't use
the ORM, but I still was able to connect to the MSSQL DB from my
django app using raw queries.

On Wed, Apr 18, 2018 at 8:55 AM, Matthew Pava <matthew.p...@iss.com> wrote:
> Hi Chris,
>
> SQL Server is not one of the databases that Django supports out of the box.
> There are third party packages available, though, but I haven’t tested any
> of them with recent versions.
>
> Saying that, you can create views in your database backend.  In your
> migrations file, use the RunSQL operation.
>
> https://docs.djangoproject.com/en/2.0/ref/migration-operations/#runsql
>
>
>
> In your models file, change the Meta option, managed, to False.
>
> https://docs.djangoproject.com/en/2.0/ref/models/options/#managed
>
>
>
> Good luck!
>
>
>
> As for stored procedures and functions, I haven’t worked enough with those
> mixed in with Django to give you much guidance except to do some more
> searching on the web.  And I would also advise against using them so that
> you can keep your code in your Django project.  I haven’t found a need for
> them myself while using Django.
>
>
>
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com]
> On Behalf Of Chris Wedgwood
> Sent: Wednesday, April 18, 2018 1:50 AM
> To: django-users@googlegroups.com
> Subject: Adding stored procedures
>
>
>
> Hi All
>
>
>
> I am using SQL SERVER in my latest django project and I am going to be using
> some stored procedures.
>
>
>
> My question is about how to go about deploying stored procedure changes with
> django. I have looked through the migrations documentation which looks very
> specific to model changes.
>
>
>
> Has anyone had experience of having to create other things such a stored
> procedures/views/functions?
>
>
>
> thanks
>
> Chris
>
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACQBJYU5CDhCrP7cNRpzp7fRDr1pyf48css-EaVW%3Drj65SmEsg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/58f5f935832647b0afd58ac5105b45f0%40ISS1.ISS.LOCAL.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY4OOb3HufKYQ8v2y5cUGgVWmhzBTMgO6hn%2BEO%3Dwi9swww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding stored procedures

2018-04-19 Thread Jani Tiainen
Hi.

Django migrations are run only once. If you want to change you stored
procedure you always need a new migration.

In case of being last migration you could develop it by having drop clause
im reverse migration. But if there is another migration(s) between current
and new stored procedure you need to create new migration.

One option could be to hook pre- or post migration signal and apply your
stored procedure there.


to 19. huhtikuuta 2018 klo 17.02 Chris Wedgwood 
kirjoitti:

> Thanks Matthew
>
> I probably need to think about this some more
>
> I think using runsql will work. Do you know if you can set migrations to
> be rerunnable? It would be useful to be able to change something like a
> stored procedure and then it gets dropped and recreated each deployment
>
> Saying that the stored procedure is going to be used for an import task
> that isn't actually related to Django so probably needs to be deployed  by
> another mechanism and I should leave migrations for only DJango specific
> changes
>
> thanks
> Chris
>
>
>
> On Wednesday, 18 April 2018 07:50:52 UTC+1, Chris Wedgwood wrote:
>>
>> Hi All
>>
>> I am using SQL SERVER in my latest django project and I am going to be
>> using some stored procedures.
>>
>> My question is about how to go about deploying stored procedure changes
>> with django. I have looked through the migrations documentation which looks
>> very specific to model changes.
>>
>> Has anyone had experience of having to create other things such a stored
>> procedures/views/functions?
>>
>> thanks
>> Chris
>>
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20a5ed5a-97f4-413b-8700-58606b781a2f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91odLVAXZBkf8_VAdsRHU%2Biz11H73vzoRE-5dVB7QbHFA_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: Adding stored procedures

2018-04-19 Thread Matthew Pava
Hi Chris,
The migrations will be run whenever you execute the migrate command.  When I 
want to make changes to an unmanaged model, in the next migration file I add a 
DROP statement to RunSQL, and then the new code to generate the VIEW.  I 
haven’t attempted reversing a migration, though.  I try to test with the new 
migration before deploying to production.
Best wishes,
Matthew

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Chris Wedgwood
Sent: Thursday, April 19, 2018 9:02 AM
To: Django users
Subject: Re: Adding stored procedures

Thanks Matthew

I probably need to think about this some more

I think using runsql will work. Do you know if you can set migrations to be 
rerunnable? It would be useful to be able to change something like a stored 
procedure and then it gets dropped and recreated each deployment

Saying that the stored procedure is going to be used for an import task that 
isn't actually related to Django so probably needs to be deployed  by another 
mechanism and I should leave migrations for only DJango specific changes

thanks
Chris



On Wednesday, 18 April 2018 07:50:52 UTC+1, Chris Wedgwood wrote:
Hi All

I am using SQL SERVER in my latest django project and I am going to be using 
some stored procedures.

My question is about how to go about deploying stored procedure changes with 
django. I have looked through the migrations documentation which looks very 
specific to model changes.

Has anyone had experience of having to create other things such a stored 
procedures/views/functions?

thanks
Chris




--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20a5ed5a-97f4-413b-8700-58606b781a2f%40googlegroups.com<https://groups.google.com/d/msgid/django-users/20a5ed5a-97f4-413b-8700-58606b781a2f%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/373c82f3da11492182afcb2ee961d0fd%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Adding stored procedures

2018-04-19 Thread Chris Wedgwood
Thanks Matthew

I probably need to think about this some more

I think using runsql will work. Do you know if you can set migrations to be 
rerunnable? It would be useful to be able to change something like a stored 
procedure and then it gets dropped and recreated each deployment

Saying that the stored procedure is going to be used for an import task 
that isn't actually related to Django so probably needs to be deployed  by 
another mechanism and I should leave migrations for only DJango specific 
changes

thanks
Chris
 


On Wednesday, 18 April 2018 07:50:52 UTC+1, Chris Wedgwood wrote:
>
> Hi All
>
> I am using SQL SERVER in my latest django project and I am going to be 
> using some stored procedures.
>
> My question is about how to go about deploying stored procedure changes 
> with django. I have looked through the migrations documentation which looks 
> very specific to model changes.
>
> Has anyone had experience of having to create other things such a stored 
> procedures/views/functions?
>
> thanks
> Chris
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20a5ed5a-97f4-413b-8700-58606b781a2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Adding stored procedures

2018-04-18 Thread Matthew Pava
Hi Chris,
SQL Server is not one of the databases that Django supports out of the box.  
There are third party packages available, though, but I haven’t tested any of 
them with recent versions.
Saying that, you can create views in your database backend.  In your migrations 
file, use the RunSQL operation.
https://docs.djangoproject.com/en/2.0/ref/migration-operations/#runsql

In your models file, change the Meta option, managed, to False.
https://docs.djangoproject.com/en/2.0/ref/models/options/#managed

Good luck!

As for stored procedures and functions, I haven’t worked enough with those 
mixed in with Django to give you much guidance except to do some more searching 
on the web.  And I would also advise against using them so that you can keep 
your code in your Django project.  I haven’t found a need for them myself while 
using Django.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Chris Wedgwood
Sent: Wednesday, April 18, 2018 1:50 AM
To: django-users@googlegroups.com
Subject: Adding stored procedures

Hi All

I am using SQL SERVER in my latest django project and I am going to be using 
some stored procedures.

My question is about how to go about deploying stored procedure changes with 
django. I have looked through the migrations documentation which looks very 
specific to model changes.

Has anyone had experience of having to create other things such a stored 
procedures/views/functions?

thanks
Chris




--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACQBJYU5CDhCrP7cNRpzp7fRDr1pyf48css-EaVW%3Drj65SmEsg%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CACQBJYU5CDhCrP7cNRpzp7fRDr1pyf48css-EaVW%3Drj65SmEsg%40mail.gmail.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/58f5f935832647b0afd58ac5105b45f0%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Adding stored procedures

2018-04-18 Thread Chris Wedgwood
Hi All

I am using SQL SERVER in my latest django project and I am going to be
using some stored procedures.

My question is about how to go about deploying stored procedure changes
with django. I have looked through the migrations documentation which looks
very specific to model changes.

Has anyone had experience of having to create other things such a stored
procedures/views/functions?

thanks
Chris

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACQBJYU5CDhCrP7cNRpzp7fRDr1pyf48css-EaVW%3Drj65SmEsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: adding stored procedures / postgres functions to db?

2006-05-11 Thread mazurin

Hi Malcolm,

  Got it. That's all I need to know.

  Thanks!

Mikah

--


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: adding stored procedures / postgres functions to db?

2006-05-11 Thread Malcolm Tredinnick

Hi Mikah,

On Wed, 2006-05-10 at 23:29 -0700, mazurin wrote:
> Malcolm and Adrian,
> 
>   Thanks so much for your quick replies! I thought of that, but I
> didn't know if it was the Djangoic way of doing it.

You're welcome. :-)

>   Follow up question -- are _all_ the files in the sql/ directory
> executed, or just those that have the same names as the models?

Just those that match the model class names. And to head off a related
question: the order they are executed in is, as far as I can see,
arbitrary; the only guarantee is that all the tables for all the models
will already have been created.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: adding stored procedures / postgres functions to db?

2006-05-11 Thread mazurin

Malcolm and Adrian,

  Thanks so much for your quick replies! I thought of that, but I
didn't know if it was the Djangoic way of doing it.

  Follow up question -- are _all_ the files in the sql/ directory
executed, or just those that have the same names as the models?

mikah

--


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: adding stored procedures / postgres functions to db?

2006-05-10 Thread Adrian Holovaty

On 5/10/06, mazurin <[EMAIL PROTECTED]> wrote:
>   My question is, how do I add the CREATE FUNCTION statement to
> Django's db-creating process? For initial data, I know that I just make
> a bunch of .sql files that have the same name as the models, and put
> them inside the sql/ directory. Is there something similar I can do for
> functions?

Hi Mikah,

Those .sql files that you put in the sql/ directory can contain
arbitrary SQL, including CREATE FUNCTION statements. So go right ahead
and put your function(s) in there.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: adding stored procedures / postgres functions to db?

2006-05-10 Thread Malcolm Tredinnick

On Wed, 2006-05-10 at 06:20 -0700, mazurin wrote:
> 
> Hi,
> 
>   I'm trying to implement a complicated sequence of updates inside a
> form-handling view, and I realized that it might be best to do it
> inside a Postgresql function. In fact, I've already found sample code
> for a postgres function that's almost exactly what I need.
> 
>   My question is, how do I add the CREATE FUNCTION statement to
> Django's db-creating process? For initial data, I know that I just make
> a bunch of .sql files that have the same name as the models, and put
> them inside the sql/ directory. Is there something similar I can do for
> functions?

All of the initial data is inserted after all the tables have been
created. So you can put your stored procedure creation code in the
initial SQL data file for (any) one of your models. There is no generic
initial data file that is read, so this would seem to be the simplest
solution.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



adding stored procedures / postgres functions to db?

2006-05-10 Thread mazurin


Hi,

  I'm trying to implement a complicated sequence of updates inside a
form-handling view, and I realized that it might be best to do it
inside a Postgresql function. In fact, I've already found sample code
for a postgres function that's almost exactly what I need.

  My question is, how do I add the CREATE FUNCTION statement to
Django's db-creating process? For initial data, I know that I just make
a bunch of .sql files that have the same name as the models, and put
them inside the sql/ directory. Is there something similar I can do for
functions?

  Thanks! I hope this isn't a dumb question.

Mikah

--


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---