<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tural Muradov on Medium]]></title>
        <description><![CDATA[Stories by Tural Muradov on Medium]]></description>
        <link>https://medium.com/@turall?source=rss-b3759133c0c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ba7VAmxYiSs761d1.jpg</url>
            <title>Stories by Tural Muradov on Medium</title>
            <link>https://medium.com/@turall?source=rss-b3759133c0c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:13:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@turall/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[MadMigration]]></title>
            <link>https://turall.medium.com/madmigration-d7d31c7bcb15?source=rss-b3759133c0c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7d31c7bcb15</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sqlalchemy]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Tural Muradov]]></dc:creator>
            <pubDate>Mon, 15 Feb 2021 17:02:18 GMT</pubDate>
            <atom:updated>2021-02-15T17:02:18.677Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d2D-X7-ieU9-LMXZBqmjUg.jpeg" /></figure><blockquote>I would like to introduce a recently started open source project designed for database migration. Why would we need such a tool when there are many database migration tools that exist? Let’s dive into details. We were asked to add some new features to a project which was made back in time. Upon entering the project we realized that the database structure was not designed very well, had complicated issues on tables. We decided to redesign the database structure and keep data as it was.<br>We looked at many tools to produce solution for this case, however, they did operate almost the same. Basically, the procedure of the tools, obtaining old database structure and convert data types,change structure of database and transfer it to another database. We have designed new database structure and our main goal to keep data. We needed to take data from different tables and transfer them to a new table. For sure, another option could be dumping old database and change everthing there and import it into new a database. Fortunately we did not apply this tecnnique, we decided to make a tool that does all of it. That is where story begins <a href="https://github.com/MadeByMads/mad-migration">MadMigration</a>.</blockquote><p>MadMigration is written entirely in python. We used the power of the <a href="https://www.sqlalchemy.org/">SQLAlchemy</a> library. In this tutorial, we will explain the details of how to use MadMigration.</p><h4>Installation</h4><pre>pip install madmigration<br>or<br>pip3 install -U madmigration</pre><p>You can check version:</p><pre>madmigration -version</pre><p>Let’s get start.</p><p>For example you have old <strong>MySQL</strong> database table with name <strong><em>user</em></strong> :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7da825fcc0e240f627224b051c4ba685/href">https://medium.com/media/7da825fcc0e240f627224b051c4ba685/href</a></iframe><p>And you want to migrate this table to new postgresql table with different column names:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d60ce22b7ec68ddd5ddad10f1f2df10b/href">https://medium.com/media/d60ce22b7ec68ddd5ddad10f1f2df10b/href</a></iframe><p>Then create <strong>yaml</strong> file <strong>schema.yml</strong> for declaring tables and columns. At first stage add <strong>Configs</strong> section. This section is for connecting to database. <strong>Configs</strong> section have two subsections <strong>SourceConfig</strong>,<strong>DestinationConfig</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1493a0f8be6425ef0e5a1a0640efc92b/href">https://medium.com/media/1493a0f8be6425ef0e5a1a0640efc92b/href</a></iframe><p>The <strong>migrationTables</strong> section is intended to describe information about tables:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ffe92390b65be417086ca79d02222b8/href">https://medium.com/media/9ffe92390b65be417086ca79d02222b8/href</a></iframe><p>Nextly, write information about columns in <strong>MigrationColumns</strong> section.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ad32697de6bb3b58d0429327ccae706/href">https://medium.com/media/4ad32697de6bb3b58d0429327ccae706/href</a></iframe><p>In case of creating a <strong>foreign</strong> <strong>key</strong> you can specify it in the column parameters. By defining <strong>foreign key</strong> options, such as <strong>ondelete,onupdate</strong>. The <strong>table_name</strong> parameter is a reference to the table, <strong>column_name</strong> is the name of the referenced column.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe5d86c60de9777efc8d686278732f31/href">https://medium.com/media/fe5d86c60de9777efc8d686278732f31/href</a></iframe><p>No options added sourceColumn section, however in destinationColumn section we could have <strong>primary_key,nullable,default,index,unique,autoincrement,foreign_key,length,type_cast options</strong>. The final yaml sturtcure will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eef55e9a36cce0c7dfdc3a857155de10/href">https://medium.com/media/eef55e9a36cce0c7dfdc3a857155de10/href</a></iframe><p>In addition, you can migrate your data from <strong>RDBMS</strong> to <strong>NOSQL</strong>. Below a small example for migration data from <strong>PostgreSQl</strong> to <strong>MongoDB</strong>. Work on <strong>PostgreSQL</strong> to <strong>MongoDB</strong> still goes, we will add other features as soon as possible.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ef935beefbf5cd63cd785b93e4bc17d/href">https://medium.com/media/7ef935beefbf5cd63cd785b93e4bc17d/href</a></iframe><p>Upon finishing declaration of yaml file run the following command.</p><pre>madmigrate -f schema.yaml</pre><p>Alternatively, you can separate migration logic into multiple <strong>.yaml</strong> or <strong>.json</strong> files. Importantly, one main <strong>.yaml</strong> file should exist, other files should be imported into this main file.</p><p><strong>main.yaml</strong> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e55d55b002335480f6576fb20df09014/href">https://medium.com/media/e55d55b002335480f6576fb20df09014/href</a></iframe><p><strong>company.yaml</strong> file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db8be576ee89cc297221ed638df2fac9/href">https://medium.com/media/db8be576ee89cc297221ed638df2fac9/href</a></iframe><p><strong>op_conds.json</strong> file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6898151ebbffc5ed24ace14e40b75ead/href">https://medium.com/media/6898151ebbffc5ed24ace14e40b75ead/href</a></iframe><p>We are not currently fully implemented all functionality for <strong>SQL</strong> and <strong>NoSQL</strong>, therefore we are still developing and adding new features on it. <br>Thank you for amazing work to our <a href="https://github.com/MadeByMads/mad-migration/graphs/contributors"><strong>team</strong></a> for implementing this tool.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7d31c7bcb15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@staticmethod vs @classmethod in Python]]></title>
            <link>https://turall.medium.com/staticmethod-vs-classmethod-in-python-c9ad472afab6?source=rss-b3759133c0c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9ad472afab6</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Tural Muradov]]></dc:creator>
            <pubDate>Wed, 29 Jan 2020 12:01:12 GMT</pubDate>
            <atom:updated>2020-01-29T20:38:19.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nBK3oux6ue1Mzt83GvQDMA.jpeg" /></figure><blockquote><strong>AzerbaijanPUG/Dev qrupu adından.</strong></blockquote><p>Yeni başlayanların ən çox anlamadığı və ya işləmə metodikasını başa düşmədiyi mövzulardan biridə python dilində class-ların @staticmethod və @classmethod dekoratorlarıdır. Dekoratorlar haqqında öz ana dilimizdə ətraflı <a href="https://nicat.org/oxu/5">bu linkdən</a> oxuya bilərsiniz.</p><blockquote><strong>@staticmethod</strong></blockquote><p>Static metodlar class-ın nə obyektindən,nə onun property-lərindən nədəki metodlarından asılı olmayan sərbəst bir metoddur. Ümumilikdə statik metodlar class-ın obyektindən yox bir başa class-ın özündən asılıdır və obyektlərinin vəziyyətindən asılı olmur. Qısası class-ın heç bir törəməsindən asılı deyil. Static metodların class barədə hec bir anlayışı olmur, yalnız öz arqumentlərindən xəbəri olur. Static metodların işlənmə yerləri çoxda geniş olmasada məna baxımından class-ın gördüyü işə yaxın olan köməkçi metodları onunla yazmaq daha məqsədə uyğundur. Qısa kod nümunələrini aşagıdakı linkdə yerləşdirdim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b675afe56b51d440f52b2434acea505/href">https://medium.com/media/4b675afe56b51d440f52b2434acea505/href</a></iframe><p>Yuxarıdakı nümunədən də göründüyü kimi static metodların classin hec bir törəməsi ilə əlaqesi yoxdur (print funksiyasının nəticələrinə baxın).</p><blockquote><strong>@classmethod</strong></blockquote><p>classmethod-da staticmethod kimi class-ın obyektinə yox , class-ın özunə bağlı olur. Classmethod class-ın özü ilə işləyir,ona görədə birinci arqument kimi class-ın (cls) özü qəbul olunur . Bu dekorator daha cox Fabrika metodu adlanır (Factory methods o metodlardır ki, class-ın öz obyektini qaytarır). Class-ın konstruktorunu da (<strong>constructor</strong>) Fabrika metodu adlandırmaq olar. Qısa kod nümunələrini aşagıdakı linkdə yerləşdirdim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23a0185202d526c058c97b34b7bfc3e9/href">https://medium.com/media/23a0185202d526c058c97b34b7bfc3e9/href</a></iframe><p>Gördüyümüz kimi pythonun isinstance metodu gösterir ki, statik metodla qaytarılan string-lər CustomString class-nın törəməsi deyil, amma classmethod-la yaradılan string-lər isə True nəticə qaytarır. Burdan belə qənaətə gəlmək olar ki, obyekt CustomString class-dan törənib. Static metod kimi yaratdığımız custom_title metodu @classmethod — un daxilində də köməkçi vasitə kimi istifadə etmişik.</p><blockquote><strong>Bəlkə daha real proyektdə işlədilən bir misala baxaq? ☺️</strong></blockquote><p>Deməli, təsəvvür edək ki, <a href="http://flask.palletsprojects.com/en/1.1.x/">Flask micro web framework</a> və <a href="https://docs.sqlalchemy.org/en/13/">SQLAlchemy</a> istifadə edərək xırda bir CRUD yazdım(Kodun başa düşülməsi üçün ayrı fayllara bölmədim). Kod parçasina aşagıdakı linkdən baxa bilərsiz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65b4dd57ce1177992b1fa8fda38d6fb9/href">https://medium.com/media/65b4dd57ce1177992b1fa8fda38d6fb9/href</a></iframe><p>CRUD class-na nəzər yetirsək görərik ki, bir neçə @classmethod istifadə edilir. Gəlin ilk öncə create metoduna nəzər yetirək. Niyə classmethod istifadə olunub? Ona görəki adi halda biz db-dəki cədvələ məlumat ötürdüyümüz zaman gərək hər zaman həmin modelin obyektini yaradaq və bir-bir user-in məlumatlarını daxil edək. Daha sonra isə save ve commit metodları vasitəsi ilə, məlumatları db-yə yazaq. Ancaq classmethodun köməkliyi ilə biz bu problemi aradan qaldırırıq. Üstəlik id dəyişənini də yoxlayırıq, olmadığı halda əlavə edirik. Biz classmethod istifadə etdiyimizə görə çağrıldığı class-ı, arqument kimi ötürdüyünə görə heç bir yoxlanışa ehtiyac qalmır. Ötürülən məlumatlar həmin modelə uyğun yerləşdirilir. Keçək digər classmetodlara, filter_first və query_all. Digər classmethod-da olduğu kimi bu halda da biz bu metodları çağırdığımız modelə uyğun olaraq query-i hazırlanır. SqlAlchemy-inin session.query() metodu query-i hazırlamaq üçün model ötürülməsini tələb edir. Bu zaman köməyimizə @classmethod dekoratoru gəlir. Bu bizə imkan verir ki, əlavə kod yazmayaraq modellərimizdən bir başa bu metoda müraciət edək. Müraciət zamanı classmethod özu çağrılan class-ı birinci arqument kimi ötürür və biz ona görə query hazırlayıb icra edirik.</p><p>İndi isə yuxarıda göstərdiyimiz kodun classmethod-suz yazılışına aşağıdakı linkdən baxaq.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a6d6150b6213da66c1501e7b1b24673/href">https://medium.com/media/7a6d6150b6213da66c1501e7b1b24673/href</a></iframe><p>Koda nəzər yetirsək nə qədər artıq kod yazıldığını görmək olar. Həmin hissələri kodda şərhlərlə göstərilib.</p><blockquote><strong>Qeyd</strong></blockquote><p>Yuxarıdakı kodlar tam işlək deyil. Real proyektdən bir hissələrdi sadəcə.</p><blockquote><strong>Nəticə</strong></blockquote><p><strong>Oxşarlıqları</strong>:</p><p>1) Hər ikisi class metodudur.</p><p>2) Hər ikisini class-ın obyektindən yox class-in özündən çağırmaq olur.</p><p><strong>Fərqləri</strong>:</p><p>1) @staticmethod class-la heç bir əlaqəsi yoxdur yalnız köməkçidir.</p><p>2) @classmethod class-in obyektini qaytarır bizə və class-ın obyekti ilə işləyir.</p><blockquote><strong>Extra</strong></blockquote><p>Class-da tez-tez rast gəlinən self və cls dəyişən adları heç bir məna kəsb etmir, siz onları istəyinizə uyğun olaraq dəyişə bilərsiz , vacib deyil (amma bunu etmeyin ☺️). self və cls dəyişən adları proqramçılar arasında kodu oxuduqda anlaşıqlı və aydın olması üçün işlədilir (<a href="https://www.investopedia.com/terms/b/best_practices.asp">Best Practices</a>).</p><blockquote>Yararlı linklər</blockquote><ul><li><a href="https://docs.sqlalchemy.org/en/13/orm/session_basics.html">SQLAlchemy 1.4 Documentation</a></li><li><a href="https://flask-sqlalchemy.palletsprojects.com/en/2.x/quickstart/">Quickstart - Flask-SQLAlchemy Documentation (2.x)</a></li><li><a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world">The Flask Mega-Tutorial Part I: Hello, World!</a></li><li><a href="https://flask-migrate.readthedocs.io/en/latest/">Flask-Migrate</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9ad472afab6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>