8000 chore: [alt] Code refactoring to follow common Google API scheme --- tryout! by mf2199 · Pull Request #486 · googleapis/python-spanner-django · GitHub
[go: up one dir, main page]

Skip to content

chore: [alt] Code refactoring to follow common Google API scheme --- tr 8000 yout! #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
django-spanner
==============
django-google-spanner
=====================

ORM plugin for using Cloud Spanner as a database for Django.

Expand Down Expand Up @@ -37,12 +37,12 @@ Table of contents
Installing it
-------------

Use the version of django-spanner that corresponds to your version of
Django. For example, django-spanner 2.2.x works with Django 2.2.y. (This
Use the version of django-google-spanner that corresponds to your version of
Django. For example, django-google-spanner 2.2.x works with Django 2.2.y. (This
is the only supported version at this time.)

The minor release number of Django doesn't correspond to the minor
release number of django-spanner. Use the latest minor release of each.
release number of django-google-spanner. Use the latest minor release of each.

.. code:: shell

Expand All @@ -54,13 +54,13 @@ Using it
After `installing it <#installing-it>`__, you'll need to edit your
Django ``settings.py`` file:

- Add ``django_spanner`` as the very first entry in the
- Add ``django_google_spanner`` as the very first entry in the
``INSTALLED_APPS`` setting

.. code:: python

INSTALLED_APPS = [
'spanner_django',
'django_google_spanner',
...
]

Expand All @@ -73,7 +73,7 @@ Format

DATABASES = {
'default': {
'ENGINE': 'spanner_django',
'ENGINE': 'django_google_spanner',
'PROJECT': '<project_id>',
'INSTANCE': '<instance_id>',
'NAME': '<database_name>',
Expand All @@ -94,7 +94,7 @@ For example:

DATABASES = {
'default': {
'ENGINE': 'spanner_django',
'ENGINE': 'django_google_spanner',
'PROJECT': 'appdev-soda-spanner-staging', # Or the GCP project-id
'INSTANCE': 'django-dev1', # Or the Cloud Spanner instance
'NAME': 'db1', # Or the Cloud Spanner database to use
Expand All @@ -107,15 +107,15 @@ Limitations
Transaction management isn't supported
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

django-spanner always works in Django's default transaction behavior,
django-google-spanner always works in Django's default transaction behavior,
``autocommit`` mode. Transactions cannot be controlled manually with
calls like ``django.db.transaction.atomic()``.

``AutoField`` generates random IDs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spanner doesn't have support for auto-generating primary key values.
Therefore, django-spanner monkey-patches ``AutoField`` to generate a
Therefore, django-google-spanner monkey-patches ``AutoField`` to generate a
random UUID4. It generates a default using ``Field``'s ``default``
option which means ``AutoField``\ s will have a value when a model
instance is created. For example:
Expand All @@ -136,7 +136,7 @@ were created.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spanner doesn't support ``ON DELETE CASCADE`` when creating foreign-key
constraints so django-spanner `doesn't support foreign key
constraints so django-google-spanner `doesn't support foreign key
constraints <https://github.com/googleapis/python-spanner-django/issues/313>`__.

Check constraints aren't supported
Expand Down Expand Up @@ -185,7 +185,7 @@ Spanner has some limitations on schema changes which you must respect:
- Renaming tables and columns isn't supported.
- A column's type can't be changed.
- A table's primary key can't be altered.
- Migrations aren't atomic since django-spanner doesn't support
- Migrations aren't atomic since django-google-spanner doesn't support
transactions.

``DurationField`` arithmetic doesn't work with ``DateField`` values (`#253 <https://github.com/googleapis/python-spanner-django/issues/253>`__)
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions django_spanner/base.py → django_google_spanner/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

import spanner_dba 9E88 pi as Database
from django.db.backends.base.base import BaseDatabaseWrapper
from google.cloud import spanner_v1 as spanner
from google.cloud import spanner_v1 as spanner, spanner_dbapi as Database

from .client import DatabaseClient
from .creation import DatabaseCreation
Expand Down Expand Up @@ -117,7 +116,7 @@ def get_connection_params(self):
"project": self.settings_dict["PROJECT"],
"instance_id": self.settings_dict["INSTANCE"],
"database_id": self.settings_dict["NAME"],
"user_agent": "django_spanner/0.0.1",
"user_agent": "django_google_spanner/0.0.1",
**self.settings_dict["OPTIONS"],
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"fixtures_regress.tests.TestFixtures.test_loaddata_raises_error_when_fixture_has_invalid_foreign_key",
# No Django transaction management in Spanner.
"basic.tests.SelectOnSaveTests.test_select_on_save_lying_update",
# django_spanner monkey patches AutoField to have a default value.
# django_google_spanner monkey patches AutoField to have a default value.
"basic.tests.ModelTest.test_hash",
"generic_relations.test_forms.GenericInlineFormsetTests.test_options",
"generic_relations.tests.GenericRelationsTests.test_unsaved_instance_on_generic_foreign_key",
Expand Down Expand Up @@ -218,7 +218,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"admin_views.test_multidb.MultiDatabaseTests.test_delete_view",
"auth_tests.test_admin_multidb.MultiDatabaseTests.test_add_view",
"contenttypes_tests.test_models.ContentTypesMultidbTests.test_multidb",
# Tests that by-pass using django_spanner and generate
# Tests that by-pass using django_google_spanner and generate
# invalid DDL: https://github.com/orijtech/django-spanner/issues/298
"cache.tests.CreateCacheTableForDBCacheTests",
"cache.tests.DBCacheTests",
Expand Down Expand Up @@ -317,10 +317,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
# This test isn't isolated on databases like Spanner that don't
# support transactions: https://code.djangoproject.com/ticket/31413
"migrations.test_loader.LoaderTests.test_loading_squashed",
# Probably due to django-spanner setting a default on AutoField:
# Probably due to django-google-spanner setting a default on AutoField:
# https://github.com/googleapis/python-spanner-django/issues/422
"model_inheritance_regress.tests.ModelInheritanceTest.test_issue_6755",
# Probably due to django-spanner setting a default on AutoField:
# Probably due to django-google-spanner setting a default on AutoField:
# https://github.com/googleapis/python-spanner-django/issues/424
"model_formsets.tests.ModelFormsetTest.test_prevent_change_outer_model_and_create_invalid_data",
"model_formsets_regress.tests.FormfieldShouldDeleteFormTests.test_no_delete",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
from django.db.utils import DatabaseError
from django.utils import timezone
from django.utils.duration import duration_microseconds
from spanner_dbapi.parse_utils import DateStr, TimestampStr, escape_name
from google.cloud.spanner_dbapi import DateStr, TimestampStr, escape_name


class DatabaseOperations(BaseDatabaseOperations):
cast_data_types = {"CharField": "STRING", "TextField": "STRING"}
cast_char_field_without_max_length = "STRING"
compiler_module = "django_spanner.compiler"
compiler_module = "django_google_spanner.compiler"
# Django's lookup names that require a different name in Spanner's
# EXTRACT() function.
# https://cloud.google.com/spanner/docs/functions-and-operators#extract
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions django_spanner/utils.py → django_google_spanner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

def check_django_compatability():
"""
Verify that this version of django-spanner is compatible with the installed
version of Django. For example, any django-spanner 2.2.x is compatible
Verify that this version of django-google-spanner is compatible with the installed
version of Django. For example, any django-google-spanner 2.2.x is compatible
with Django 2.2.y.
"""
from . import __version__

if django.VERSION[:2] != get_version_tuple(__version__)[:2]:
raise ImproperlyConfigured(
"You must use the latest version of django-spanner {A}.{B}.x "
"with Django {A}.{B}.y (found django-spanner {C}).".format(
"You must use the latest version of django-google-spanner {A}.{B}.x "
"with Django {A}.{B}.y (found django-google-spanner {C}).".format(
A=django.VERSION[0], B=django.VERSION[1], C=__version__
)
)
File renamed without changes.
4 changes: 2 additions & 2 deletions django_test_suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ create_settings() {
cat << ! > "$SETTINGS_FILE.py"
DATABASES = {
'default': {
'ENGINE': 'django_spanner',
'ENGINE': 'django.google.spanner',
'PROJECT': "$PROJECT",
'INSTANCE': "$INSTANCE",
'NAME': "$TEST_DBNAME",
},
'other': {
'ENGINE': 'django_spanner',
'ENGINE': 'django.google.spanner',
'PROJECT': "$PROJECT",
'INSTANCE': "$INSTANCE",
'NAME': "$TEST_DBNAME_OTHER",
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
master_doc = "index"

# General information about the project.
project = u"google-cloud-spanner-django"
project = u"django-google-spanner"
copyright = u"2020, Google"
author = u"Google APIs"

Expand Down Expand Up @@ -237,7 +237,7 @@
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = "google-cloud-spanner-django-doc"
htmlhelp_basename = "django-google-spanner-doc"

# -- Options for warnings ------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/connection-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DB API Connection
Creating a Connection
---------------------

To use the API, the :class:`~google.cloud.spanner_django.connection.Connection`
To use the API, the :class:`~google.cloud.django_google_spanner.connection.Connection`
class defines a high-level interface which handles connection to a Spanner
databse:

Expand All @@ -29,4 +29,4 @@ Configuration
Engine or Google Compute Engine the project will be detected automatically.
(Setting this environment variable is not required, you may instead pass the
``project`` explicitly when constructing a
:class:`~google.cloud.spanner_django.connection.Connection`).
:class:`~google.cloud.django_google_spanner.connection.Connection`).
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ API Documentation
Changelog
---------

For a list of all ``google-cloud-spanner-django`` releases:
For a list of all ``django-google-spanner`` releases:

.. toctree::
:maxdepth: 2
Expand Down
26 changes: 13 additions & 13 deletions examples/from-scratch/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## django-spanner for Django tutorial
## django-google-spanner for Django tutorial

This example shows how to use django-spanner for Cloud Spanner as a backend database for [Django's tutorials](https://docs.djangoproject.com/en/2.2/intro/tutorial01/)
This example shows how to use django-google-spanner for Cloud Spanner as a backend database for [Django's tutorials](https://docs.djangoproject.com/en/2.2/intro/tutorial01/)

### Walkthrough the introduction to Django

### Install django-spanner
We'll need to install `django-spanner`, by cloning this repository and then running `pip3 install`
### Install django-google-spanner
We'll need to install `django-google-spanner`, by cloning this repository and then running `pip3 install`
```shell
git clone https://github.com/googleapis/django-spanner
git clone https://github.com/googleapis/django-google-spanner
pip3 install .
```

Expand All @@ -20,18 +20,18 @@ or visit this [codelab](https://opencensus.io/codelabs/spanner/#0)
### Follow the tutorial
Please follow the guides in https://docs.djangoproject.com/en/2.2/intro/tutorial01/ until the end with a single DISTINCTION:

### Update your settings.py file to use django-spanner
### Update your settings.py file to use django-google-spanner
After we have a Cloud Spanner database created, we'll need a few variables:
* ProjectID
* Instance name
* Database name aka DisplayName

Once in, please edit the file `hc/local_settings.py`, and:

a) add `django_spanner` as the very first entry to your `INSTALLED_APPS`
a) add `django_google_spanner` as the very first entry to your `INSTALLED_APPS`
```python
INSTALLED_APPS = [
'django_spanner', # Must be listed first.
'django_google_spanner', # Must be listed first.
...
]
```
Expand All @@ -40,7 +40,7 @@ b) update `DATABASES` into the following:
```python
DATABASES = {
'default': {
'ENGINE': 'django_spanner',
'ENGINE': 'django_google_spanner',
'PROJECT': PROJECT_ID,
'INSTANCE': SPANNER_INSTANCE,
'NAME': SPANNER_DATABASE_NAME,
Expand All @@ -59,7 +59,7 @@ which when filled out, will look like this
```python
DATABASES = {
'default': {
'ENGINE': 'django_spanner',
'ENGINE': 'django_google_spanner',
'PROJECT': 'spanner-appdev',
'INSTANCE': 'instance',
'NAME': 'healthchecks_db',
Expand Down Expand Up @@ -106,13 +106,13 @@ Running migrations:
After those migrations are completed, that will be all. Please continue on with the guides.

### Comprehensive hands-on guide
For a more comprehensive, step by step hands-on guide, please visit [using django-spanner from scratch](https://orijtech-161805.firebaseapp.com/quickstart/new_app/)
For a more comprehensive, step by step hands-on guide, please visit [using django-google-spanner from scratch](https://orijtech-161805.firebaseapp.com/quickstart/new_app/)


### References

Resource|URL
---|---
Cloud Spanner homepage|https://cloud.google.com/spanner/
django-spanner project's source code|https://github.com/googleapis/python-spanner-django/
django-spanner from scratch|https://orijtech-161805.firebaseapp.com/quickstart/new_app/
django-google-spanner project's source code|https://github.com/googleapis/python-spanner-django/
django-google-spanner from scratch|https://orijtech-161805.firebaseapp.com/quickstart/new_app/
Loading
0