Re: [sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Simon King
Did you regenerate your migration script after adding the hooks?

I would start by putting some print statements in the include_name hook to
see how it is being called. You should see it called for every object in
the database. You can then decide which names to return True for, and which
ones to return False for. The example in the docs is probably a reasonable
default:

def include_name(name, type_, parent_names):
print("Checking %s %s" % (type_, name))
if type_ == "table":
result = name in target_metadata.tables
else:
result = True
print("Returning %s" % result)
return result

Use that hook in your env.py and regenerate your migration script. You
should see output for each object in the database.

Simon


On Wed, Jun 8, 2022 at 5:59 PM Vishal Shimpi 
wrote:

> Thank you Simon for your response. yes i am using autogenerate feature. i
> tried with include_object and include_name hooks. but it won't work for me.
> after adding hook also alembic touches to existing tables..
>
> if you send the code snipet for env.py file.. that will really help me..
>
> Thank you.
>
> On Wed, 8 Jun 2022, 10:00 pm Simon King,  wrote:
>
>> If I understand correctly, you used Alembic's "autogenerate" feature to
>> create your migration script. This feature compares the table definitions
>> in your application with the table definitions in the database and then
>> generates a script to alter the database to match your application.
>>
>> You can instruct alembic to ignore certain objects in the database using
>> either the "include_name" or "include_object" hooks:
>>
>>
>> https://alembic.sqlalchemy.org/en/latest/autogenerate.html#controlling-what-to-be-autogenerated
>>
>> The first example there ("Omitting Table Names from the Autogenerate
>> Process") is probably what you want.
>>
>> Hope that helps,
>>
>> Simon
>>
>> On Wed, Jun 8, 2022 at 3:15 PM Vishal Shimpi 
>> wrote:
>>
>>> I am working on fastapi, in which i have created models and i am inteded
>>> to create the table in sql server database, however when i am runing my
>>> first migration, alembic detected removal of existing table which are not
>>> belongs to my work. Can somebody help how i can create my tables and avoid
>>> others tables to be removed and recreated again
>>>
>>> --
>>> SQLAlchemy -
>>> The Python SQL Toolkit and Object Relational Mapper
>>>
>>> http://www.sqlalchemy.org/
>>>
>>> To post example code, please provide an MCVE: Minimal, Complete, and
>>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>>> description.
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "sqlalchemy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to sqlalchemy+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sqlalchemy/3a89be66-24a0-4215-8b00-b4c11c52bbf9n%40googlegroups.com
>>> 
>>> .
>>>
>> --
>> SQLAlchemy -
>> The Python SQL Toolkit and Object Relational Mapper
>>
>> http://www.sqlalchemy.org/
>>
>> To post example code, please provide an MCVE: Minimal, Complete, and
>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>> description.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sqlalchemy+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/CAFHwexfFR%2Basd7oT8Lskimf-NqvDTs7cY--PLXf_5HQfrunwbw%40mail.gmail.com
>> 
>> .
>>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CAP1EvouY3YatLWQSJWnpPszZ20ixLqhAJbA_y-TQq60kKinjPg%40mail.gmail.com
> 
> .
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a 

Re: [sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Vishal Shimpi
Thank you Simon for your response. yes i am using autogenerate feature. i
tried with include_object and include_name hooks. but it won't work for me.
after adding hook also alembic touches to existing tables..

if you send the code snipet for env.py file.. that will really help me..

Thank you.

On Wed, 8 Jun 2022, 10:00 pm Simon King,  wrote:

> If I understand correctly, you used Alembic's "autogenerate" feature to
> create your migration script. This feature compares the table definitions
> in your application with the table definitions in the database and then
> generates a script to alter the database to match your application.
>
> You can instruct alembic to ignore certain objects in the database using
> either the "include_name" or "include_object" hooks:
>
>
> https://alembic.sqlalchemy.org/en/latest/autogenerate.html#controlling-what-to-be-autogenerated
>
> The first example there ("Omitting Table Names from the Autogenerate
> Process") is probably what you want.
>
> Hope that helps,
>
> Simon
>
> On Wed, Jun 8, 2022 at 3:15 PM Vishal Shimpi 
> wrote:
>
>> I am working on fastapi, in which i have created models and i am inteded
>> to create the table in sql server database, however when i am runing my
>> first migration, alembic detected removal of existing table which are not
>> belongs to my work. Can somebody help how i can create my tables and avoid
>> others tables to be removed and recreated again
>>
>> --
>> SQLAlchemy -
>> The Python SQL Toolkit and Object Relational Mapper
>>
>> http://www.sqlalchemy.org/
>>
>> To post example code, please provide an MCVE: Minimal, Complete, and
>> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>> description.
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sqlalchemy+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sqlalchemy/3a89be66-24a0-4215-8b00-b4c11c52bbf9n%40googlegroups.com
>> 
>> .
>>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CAFHwexfFR%2Basd7oT8Lskimf-NqvDTs7cY--PLXf_5HQfrunwbw%40mail.gmail.com
> 
> .
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAP1EvouY3YatLWQSJWnpPszZ20ixLqhAJbA_y-TQq60kKinjPg%40mail.gmail.com.


Re: [sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Simon King
If I understand correctly, you used Alembic's "autogenerate" feature to
create your migration script. This feature compares the table definitions
in your application with the table definitions in the database and then
generates a script to alter the database to match your application.

You can instruct alembic to ignore certain objects in the database using
either the "include_name" or "include_object" hooks:

https://alembic.sqlalchemy.org/en/latest/autogenerate.html#controlling-what-to-be-autogenerated

The first example there ("Omitting Table Names from the Autogenerate
Process") is probably what you want.

Hope that helps,

Simon

On Wed, Jun 8, 2022 at 3:15 PM Vishal Shimpi 
wrote:

> I am working on fastapi, in which i have created models and i am inteded
> to create the table in sql server database, however when i am runing my
> first migration, alembic detected removal of existing table which are not
> belongs to my work. Can somebody help how i can create my tables and avoid
> others tables to be removed and recreated again
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/3a89be66-24a0-4215-8b00-b4c11c52bbf9n%40googlegroups.com
> 
> .
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexfFR%2Basd7oT8Lskimf-NqvDTs7cY--PLXf_5HQfrunwbw%40mail.gmail.com.


[sqlalchemy] how i can avoid the existing database table while generating the initial revision using alembic

2022-06-08 Thread Vishal Shimpi
I am working on fastapi, in which i have created models and i am inteded to 
create the table in sql server database, however when i am runing my first 
migration, alembic detected removal of existing table which are not belongs 
to my work. Can somebody help how i can create my tables and avoid others 
tables to be removed and recreated again 

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/3a89be66-24a0-4215-8b00-b4c11c52bbf9n%40googlegroups.com.